I am writing a piece of code where @Variant is provided. I wanted to store multiple values by capturing them in a variable (runtime) and pass them in the WHERE clause. Share the logic
DECLARE @Variant VARCHAR(50)
SET @Variant='''25'',''33'''
SELECT @Variant ---- which is actually '25','33'
SELECT 'TRUE' WHERE '25' IN (@Variant)
DECLARE @Variant VARCHAR(50)
SET @Variant='''25'',''33'''
SELECT @Variant ---- which is actually '25','33'
SELECT 'TRUE' WHERE '25' IN (SELECT @Variant)
Above queries do not work...
--DECLARE @Variant VARCHAR(50)
--SET @Variant='''25'',''33'''
--SELECT @Variant
SELECT 'TRUE' WHERE '25' IN ('25','33')
Above is a simpler query in SQL Server -which I tried if SQL accepts. My actual query is to pass wild cards in the LIKE statement in WHERE clause.
DECLARE @Variant VARCHAR(50)
SET @Variant='''25%'' OR [Item_No] LIKE ''33%'''
SELECT @Variant
SELECT * from Table1 WHERE [Item_No] LIKE (@Variant) --I presume @variable will be replaced with its value during execution.
Anyways, simpler way - I have a Item_No in the Where clause to which i want to supply multiple wild cards. Is there a method similar to inline function, which should replace the text at the @variant and execute combining it.