0

How can I pass a string value within a concat statement?

for example, I want the following string: My name is 'XYZ'

The sql script for this will be:

select concat 'My name is' + 'XYZ'

In the output of the above script, the string XYZ will not be in quotes. Can someone please help me with this.

Jenna
  • 71
  • 1
  • 6
  • This question seems like it was attempting to do a `CONTACT()` function, i.e. Concat statement. So, I'm not so sure this question is actually a duplicate, but I think some of those answers are applicable. – Brett Caswell Nov 06 '19 at 08:17

1 Answers1

-3

Double up single quotes to include them in a string:

select 'My name is' + '''XYZ'''
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • not sure what merited these down votes.. `''` is escaping, thus `'''XYZ'''` does result in `'XYZ'` varchar\string. which is what you would use with `Select CONCAT('My name is ', '''XYZ''')` ... note that this answer's approach, which is correct, is not on the source question. perhaps it's worth adding there. – Brett Caswell Nov 06 '19 at 08:24
  • 4
    @BrettCaswell - answering questions which are clearly duplicates is not encouraged as it defeats the purpose of the site. – Dale K Nov 06 '19 at 08:32