How can I make this work? I want to be able to update the @result0 depending on if the variables are 0 or 1 and then put it into another set@ and then call the @result. The ##tempz table does exist. When I run this though, it just gives me : (125 row(s) affected)
DECLARE @result nvarchar(max),@result0 nvarchar(max)
SET @showstore = 1
SET @showcashier = 0
SET @showregister = 0
SET @showdate = 0
set @result = 'select '+@result0+' from ##tempz'
set @result0 = 'Amex,[Gift Card],Debit,[Off Line C.Card],[Str Cr],[House Acct],Cash,Rebate,[C.Card],VIP,Discover,[Check],MasterCard,[Visa/MC]'
If @showstore = 1
begin
set @result0 = 'StoreID,' + @result0
end
If @showcashier = 1
begin
set @result0 = 'Cashier,' + @result0
end
If @showregister = 1
begin
set @result0 = 'Register,' + @result0
end
If @showdate = 1
begin
set @result0 = 'Date,' + @result0
end
execute(@result)
You should set the value for
@resulton your last line, after all theIF..ELSE: