I'm trying to select from a table that is variable in the IF statement. Here is my question.
--ItemProcedure (stored procedure name)
--Item (table name)
Itemcode ItemName qty
--------------------------
item123 Monitor 100
item456 Laptop 50
item789 Keyboard 10
Exec ItemProcedure 'Item'
Declare @Msg as varchar(50)
IF Exists (Select * from @TableName where Itemcode = 'item123')
BEGIN
SET @Msg = 'Item exists'
END
ELSE
BEGIN
SET @Msg = 'Item not exists'
END
Select @Msg
is there any method that can do this? please advise.