troubleshooting Question

SQL Variable Problem

Avatar of emi_sastra
emi_sastra asked on
Microsoft SQL Server
6 Comments3 Solutions48 ViewsLast Modified:
Hi All,

I have below script :

DECLARE @POSITIONS VARCHAR(100) = '''SLF'', ''SRF'''

select @POSITIONS as POSITIONS
 
 SELECT 
 A.PositionCode
 FROM TMPOSITION A
 WHERE A.PositionCode IN ('SLF', 'SRF')

  SELECT 
 A.PositionCode
 FROM TMPOSITION A
 WHERE A.PositionCode IN (@POSITIONS)

The result :

POSITIONS
----------------------------------------------------------------------------------------------------
'SLF', 'SRF'

(1 row(s) affected)

PositionCode
------------
SLF 
SRF 

(2 row(s) affected)

PositionCode
------------

(0 row(s) affected)

What is wrong with @Positions ?

Thank you.
ASKER CERTIFIED SOLUTION
Éric Moreau
Senior .Net Consultant
Join our community to see this answer!
Unlock 3 Answers and 6 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 3 Answers and 6 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