Concatenating quotes to a variable/parameter value in an SQL query

Database
Enthusiast

Concatenating quotes to a variable/parameter value in an SQL query

Hi,
This is my query:

select 'tariq' from abc sample 1;
result: tariq

But if I want my output with single quotes around it how do I do that?
required result: 'tariq'

I tried this but the following did not work:
select '\'' || 'tariq' || '\'' from abc sample 1;

The above gave an error.

Please let me know as this is simple but very urgent. :-)

The real situation is as below:
Select cast(count (*) as char(8))
from ${readDB}.dw_lstg_item a, ${readDB}.dw_lstg_item_cold b
Where (cast (b.site_create_date as date) between (cast($PARAM2 as date)) and cast ((current_date - 1) as date))
and a.item_id = b.item_id
Group by 1,2;

The value of PARAM2 is a date which is being read from a text file. When the value is replaced when the code is run the single quotes do not appear around the value. I tried using || to concatenate around the PARAM2 like this:

cast('"'"' || cast($PARAM2 as char(10)) || '"'"' as date)) and cast ((current_date - 1)

Thanks.
1 REPLY
Enthusiast

Re: Concatenating quotes to a variable/parameter value in an SQL query

Alright I have it now.
The answer is to use it like this
select '''' || 'tariq' || '''' from .........