SQL Server 需要有关删除方括号的帮助,并将其作为where子句中的条件应用

voase2hg  于 2022-12-10  发布在  其他
关注(0)|答案(1)|浏览(125)

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))
z9ju0rcb

z9ju0rcb1#

你可以试试这个。但是sql注入是可能的。

select Account, Channel 
from GetMasterData 
where Account in (select [value] from STRING_SPLIT(REPLACE(REPLACE('[Amazon,Kroger,Walmart]', '[', ''),']', ''), ','))

相关问题