1

How do I create my SQL output like the following. (with , delimiter)

"1","FUZION",""

http://postimg.org/image/xehmnq5g5/

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
alexcctan
  • 123
  • 1
  • 2
  • 8

2 Answers2

0

Assuming that you are selecting data from 3 columns -

col1 = '1'
col2 = 'Fuzion'
col3 = ''
  • All 3 fields being VARCHAR & you are using SQL SERVER.

You could try something like this -

SELECT '"'+ISNULL(col1,'')+'","'+ISNULL(col2,'')+'","'+ISNULL(col3,'')+'"'

Note - If any of your field is not a VARCHAR - cast it to VARCHAR and then concatenate.

Suyash Khandwe
  • 386
  • 3
  • 11
  • by using -s "," in SQLCMD, my output result like the following 1,FUZION. All i want is "1","FUZION". Thanks – alexcctan Jan 16 '14 at 04:38
  • However, I managed to get it done by the following query Select MerchantID = +'"' + Convert(varchar(20),microsdb.CHECKS.RevCtrID) + '"', DeviceSN = +'"' + Convert(varchar(20),microsdb.CHECKS.LastWorkstationID) + '"', Many Thanks guys for the reference – alexcctan Jan 16 '14 at 08:20
0

Refer to the below script.

DECLARE @MyOrderList VARCHAR(MAX);
SET @MyOrderList = ''
SELECT @MyOrderList = ISNULL(@MyOrderList ,'') +  '"' +ColumnName + '" ,' FROM TableName

SET @MyOrderList = SUBSTRING(@MyOrderList , 1, LEN(@MyOrderList )-1)
SELECT @MyOrderList 

Hope this solves your problem.

gokul
  • 383
  • 1
  • 8