0

This value is in a column in a table:

 '962091','962092','962093'

I try to use this in a where. First I declare a variable:

DECLARE @KPLnr varchar(100)

SET @KPLnr =  CONVERT(nvarchar(max), dbo.UF_GetOption('FastecKPL')) /* here I get the values in */

If I select, I get the correct values of @KPLnr: '962091', '962092','962093', but if I try to use it in a where statement, it seems like the value is set wrong.

I get 0 results, but if I set it manually with:

WHERE c.kpl IN ('962091', '962092','962093') 

I got 414 results.

So why is WHERE c.kpl IN ('962091', '962092', '962093') not equal to WHERE c.kpl IN (@KPLnr) in my code?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Jul Pod
  • 370
  • 3
  • 16

1 Answers1

0

When an apostrophe is stored in a text column, you need to escape it by adding an extra apostrophe:

WHERE c.kpl IN ('962091'', ''962092'',''962093')
JohnHC
  • 10,935
  • 1
  • 24
  • 40