troubleshooting Question

Issue converting sql concatenate (||) in Oracle sql to Sql Server (transact-sql )

Avatar of mountiers
mountiersFlag for United Kingdom of Great Britain and Northern Ireland asked on
Microsoft SQL ServerSQL
7 Comments1 Solution72 ViewsLast Modified:

I'm trying to do in sql server something that was very easy in Oracle Sql...
select col1||'''|'''||col2||'''|'''||col3||'''|'''||col4....etc from <usertable>

and I'd end up with a string with columns separated by a pipe (|) it would cope fine with dates not needing cast or convert etc...

There doesn't seem to be the equivalent in transact-sql used within sql server.

I appreciate that I have to cast date columns but the implication is that I can use the + operator but when I do so I get the message  "Error converting varchar to numeric" implying it is trying to numerically add them together!!!
(e.g. select cast([timestamp] as varchar)+'|'+[No_]+'|'+ etc.... from <usertable> )

Any ideas what I'm doing wrong?
Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros