Reputation: 107
I have a problem here, I'm searching in stackoverflow but still not find the best way
i have a stored procedure (SP) like this
DECLARE @table NVARCHAR(max), @SQLQuery NVARCHAR(max) SET @table = @meta+'_prize4winner'
SET @SQLQuery = 'if exists (Select * from [dbo].' + @table + ' where idCampaignLog =''' + convert(nvarchar, @ID) +''') exec InsertC2CWinner''' + convert(nvarchar, @meta) +''','''+ convert(nvarchar, @ID)+''',null else select ''you lose ''as winStatus'
execute SP_EXECUTESQL @SQLQuery
need help how and where to set the output if I want the output if exist 'YOU WIN' else 'You Lose' thx
Upvotes: 0
Views: 411
Reputation: 19843
The general syntax is like this
DECLARE @retval int
DECLARE @sSQL nvarchar(500);
DECLARE @ParmDefinition nvarchar(500);
DECLARE @tablename nvarchar(50)
SELECT @tablename = N'products'
SELECT @sSQL = N'SELECT @retvalOUT = MAX(ID) FROM ' + @tablename;
SET @ParmDefinition = N'@retvalOUT int OUTPUT';
EXEC sp_executesql @sSQL, @ParmDefinition, @retvalOUT=@retval OUTPUT;
SELECT @retval;
Upvotes: 0