So I currently have the following SQL:
SELECT opportunities.ref FROM opportunities GROUP BY opportunities.ref
which returns the following results:
OP10
OP252
OP52905
OP42
I am trying to achieve the following:
'OP10'
'OP252'
'OP52905'
'OP42'
I have tried the following:
SELECT opportunities.ref FROM opportunities
CASE WHEN opportunities.ref IS NOT NULL THEN "'"+opportunitiesref+"'"
GROUP BY opportunities.ref
but this does not work.
I do not want to update the column, or use any @declare functions as this. I am currently using SQL server 2008. Im not sure how to go about this. Help?
If you are using SQL SERVER then modify your query according to below :
SELECT opportunities.ref FROM opportunities
CASE WHEN opportunities.ref IS NOT NULL THEN ''''+opportunitiesref+''''
GROUP BY opportunities.ref
If you are using SQL SERVER then refer below queries. it will work.
1)
SELECT opportunities.ref,concat('''',opportunities.ref,'''')
FROM opportunities
GROUP BY opportunities.ref
2)
SELECT opportunities.ref,
CASE WHEN opportunities.ref IS NOT NULL THEN ''''+opportunities.ref+'''' END
FROM opportunities
GROUP BY opportunities.ref
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With