Link to home
Create AccountLog in
Avatar of emi_sastra
emi_sastra

asked on

Filter using multiple value string parameter with dynamic sql script

Hi All,

I try below code.


declare @Barangcode VARCHAR(100) = '''CREPE'', ''CREPE 1018 1380'''

  DECLARE @SQL VARCHAR(MAX) = '
  SELECT BARANGCODE FROM TMBARANG
  WHERE BARANGCODE IN
  (
  SELECT ''' + REPLACE(@BarangCode, '''', '') + '''
  )  


PRINT @SQL
EXECUTE (@SQL)

What I want to achieve is show data from TMBARANG that has data 'CREPE' and CREPE 1018 1380 like below code :
 
 SELECT BARANGCODE FROM TMBARANG
  WHERE BARANGCODE IN ('CREPE', 'CREPE 1018 1380')

How could I do it ?

Thank you.
ASKER CERTIFIED SOLUTION
Avatar of lcohan
lcohan
Flag of Canada image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of emi_sastra
emi_sastra

ASKER

Hi Icohan,

In my case what should I do ?

Thank you.
Hi Icohan,

Thank you very much for your help.