Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to wrap my query output with single quotation

I often read records from my database and use notepad++ to processing the receipt in this format:

'xxxxxxxxx'    
'xxxxxxxxx',
'xxxxxxxxx',
'xxxxxxxxx'

Is there a way I can use SQL query to do this once.

Sample query I ran is:

Select ReceiptNo 
from My_table 
where TIN = 'KEYVALUE'
like image 380
kombo Avatar asked Jul 12 '13 13:07

kombo


2 Answers

This is pretty straightforward concatenation. You need to use 4 quotes here, though: the first and last are your wrapper quotes which contain the string. The inner 2 quotes are your actual quote to use, and an escape quote.

SELECT
  '''' + CAST(ReceiptNo as varchar(100)) + ''''
FROM
  My_Table
WHERE
  TIN = 'KEYVALUE'
like image 68
JNK Avatar answered Sep 20 '22 13:09

JNK


You may want to try below:

SELECT
  '''' + CAST(ReceiptNo as varchar(100)) + ''','
FROM
  My_Table
WHERE
  TIN = 'KEYVALUE'
like image 28
Nilesh Thakkar Avatar answered Sep 18 '22 13:09

Nilesh Thakkar