0

obligatory "New to T-SQL" inserted here. I'm running into an issue where an ' is in the value returned in the data and receive the error "syntax error near 'S'". below is an example of what I am trying to accomplish

CASE 
WHEN Tbl.Data = '1234 SOMETHING DR: @@That'S THE ADDRESS: @MY ADDRESS ' THEN 'That's wrong'
ELSE '' END

For the most part, this statement works and that appears to be the only real difference that I can see compared to other statements in the string. I wholeheartedly apologize if I am using the incorrect terminology and confused you further. Happens to my coworkers all the time. Ha! Thanks in advance for your time.

Squirrel
  • 23,507
  • 4
  • 34
  • 32
  • 1
    You need to escape the single quote by using two single quote, when you string contains a single quote. Your `case` expression should be : `WHEN Tbl.Data = '1234 SOMETHING DR: @@That''S THE ....` – Squirrel Apr 07 '22 at 05:42
  • By adding the two single quotes it doesn't recognize it at '@@That'S THE ADDRESS' and returns 1234 SOMETHING DR: @@That'S THE ADDRESS: @MY ADDRESS versus returning 'That's wrong' as intended. If that makes sense. It WORKS but doesn't return the desired result. – EDG_507 Apr 07 '22 at 06:16

0 Answers0