我怎样才能使这项工作?我希望能够根据变量是 0 还是 1 来更新 @result0,然后将其放入另一个 set@,然后调用 @result。##tempz 表确实存在。但是,当我运行它时,它只会给我:(受影响的 125 行)
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)