W.E.B
asked on
SQL comma
Hello,
I use below script to export data, (and save to csv through an exporter program,
the Reference field has commas in it,
when I export , the fields with commas become separated, , I need to keep the field together.
Example Reference : 100sd675,PMExvtyr
SELECT
CONVERT(varchar,InvoiceNum ber) AS [InvoiceNumber],
CONVERT(Varchar,Reference) as [Reference]
FROM FinalizedOrders
WHERE ....
I use below script to export data, (and save to csv through an exporter program,
the Reference field has commas in it,
when I export , the fields with commas become separated, , I need to keep the field together.
Example Reference : 100sd675,PMExvtyr
SELECT
CONVERT(varchar,InvoiceNum
CONVERT(Varchar,Reference)
FROM FinalizedOrders
WHERE ....
ASKER
I can't,
this is a client entry.
I found my own solution though,
'"' + Cast(Reference as varchar(100)) + '"' AS [Reference] ,
thanks
this is a client entry.
I found my own solution though,
'"' + Cast(Reference as varchar(100)) + '"' AS [Reference] ,
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I've requested that this question be deleted for the following reason:
Found own sloution
Found own sloution
Objection. Spell out what 'Found own solutions' means here, so we can accept that as the answer, so other people with similar issues can learn from this question.
ASKER
SELECT
CONVERT(varchar,InvoiceNum ber) AS [InvoiceNumber],
'"' + Cast(Reference as varchar(100)) + '"' AS [Reference]
FROM FinalizedOrders
WHERE ....
CONVERT(varchar,InvoiceNum
'"' + Cast(Reference as varchar(100)) + '"' AS [Reference]
FROM FinalizedOrders
WHERE ....
Objection? Jim he spelled out what his solution was already! Enclose the string in " ". Normal for any CSV that has commas in it.
ASKER
So , my own solution (Comment before Jim Comment)
'"' + Cast(Reference as varchar(100)) + '"' AS [Reference]
Is the same as Jim?
Jim says,
Your choices:
Change the delimeter to something else, such as pipe (|) delimited file, as pipes are hardly every used in values, except for columns that contain email text where some people's signature blocks have pipes in them, such as Dave Swift | Super Dude | Green Co.
Use the REPLACE function to either remove the commas, or replace them with some other value...
?
'"' + Cast(Reference as varchar(100)) + '"' AS [Reference]
Is the same as Jim?
Jim says,
Your choices:
Change the delimeter to something else, such as pipe (|) delimited file, as pipes are hardly every used in values, except for columns that contain email text where some people's signature blocks have pipes in them, such as Dave Swift | Super Dude | Green Co.
Use the REPLACE function to either remove the commas, or replace them with some other value...
?
ASKER
I will award the points to Jim, for his effort and time.
Thank you Jim.
Thank you Jim.
We must have cross-posted the last comment, and my objection to the close request.
SELECT
CONVERT(varchar,InvoiceNum
'!'+ CONVERT(Varchar,Reference)
FROM FinalizedOrders
WHERE ....