Need help in SQL Server. My input comes from the UI, it comes as [Amazon, Kroger, Walmart]
when multiple elements are selected.
Now the value is passed to SQL Server and the table data should be filtered and send the data back to the API.
PFB for my table data:
I tried parsing the value which is coming from UI and replace the square brackets and apply the where clause, it's not working:
select Account, Channel
from GetMasterData
where Account in ((select '''' REPLACE((select REPLACE(REPLACE('[Amazon,Kroger,Walmart]', '[', ''),']', '') as value), ',', ''',''') '''' as value))
CodePudding user response:
You can try this. But sql injection is possible.
select Account, Channel
from GetMasterData
where Account in (select [value] from STRING_SPLIT(REPLACE(REPLACE('[Amazon,Kroger,Walmart]', '[', ''),']', ''), ','))