Dynamic sql, putting a char in ''

Database
Enthusiast

Dynamic sql, putting a char in ''

Hi,

I have a delete statement that is written as a piece of dynamic sql:
SET v_lnvchCommand =
'DELETE FROM ' || v_vchTable_To_Archive ||
' WHERE week_id < ' || TRIM(LEADING FROM CAST(v_intdel_Weekly_id AS CHAR(6))) ||
' AND Ti_period_rep_id = ' || v_ti_period_rep_id;

The error occurs with v_ti_period_rep_id, which in this instance is a 'W'.
But when executing it sees
AND Ti_reporting_period_rep_id = W
and gives me the error saying it cant find column W. I have tried "" but these keep giving me an error. How can I tell teradata that this is a char?
I have tried CAST ( v_ti_period_rep_id AS CHAR(1))
2 REPLIES
Enthusiast

Re: Dynamic sql, putting a char in ''

Try this :
' AND Ti_period_rep_id = ''' || v_ti_period_rep_id || '''';
Enthusiast

Re: Dynamic sql, putting a char in ''

Cheers,

I had to use 4 ' but it worked
|| '''' || v_ti_period~-rep_id || '''';