How to wrap the output of my request with a single quote

I often read records from my database and use notepad ++ to process receipts in this format:

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

Is it possible to use an SQL query for this once.

The sample request that I ran is:

 Select ReceiptNo from My_table where TIN = 'KEYVALUE' 
+6
source share
4 answers

This is a fairly simple concatenation. You need to use 4 quotes here: the first and last are your shell quotes containing the string. The inner 2 quotation marks are your actual quote for use and a quote from the escape.

 SELECT '''' + CAST(ReceiptNo as varchar(100)) + '''' FROM My_Table WHERE TIN = 'KEYVALUE' 
+14
source

You might want to try:

 SELECT '''' + CAST(ReceiptNo as varchar(100)) + ''',' FROM My_Table WHERE TIN = 'KEYVALUE' 
+1
source
 SELECT ''''+ cast(ReceiptNo as varchar(10)) + ''',' as ReceiptNo FROM My_table WHERE TIN = 'T' 

Here is my sql script

0
source

You can use the CONCAT function to add a single quote. do as

 SELECT concat( "'", DATEBASEFIELDNAME, "'" ) 
-4
source

Source: https://habr.com/ru/post/949315/


All Articles