programer
Posting Yak Master
221 Posts |
Posted - 2013-09-30 : 20:00:17
|
if (@Type=4)beginset @StakePerBet=@Stake/7 INSERT INTO tbl_BetSlipSystem(BetSlipDetailId,Stake,Win,SystemBet) SELECT @BetSlipDetailId,@StakePerBet,0.00,Belt FROM ( SELECT Belt=STUFF(( SELECT ', ' + CAST(ID AS VARCHAR) FROM ( SELECT ROW_NUMBER() OVER(ORDER BY ID) AS Number,ID FROM inserted ) AS a WHERE a.Number IN (@B) FOR XML PATH('') ),1,2,' ') UNION SELECT Belt=STUFF(( SELECT ', ' + CAST(ID AS VARCHAR) FROM ( SELECT ROW_NUMBER() OVER(ORDER BY ID) AS Number,ID FROM inserted ) AS a WHERE a.Number IN (@A) FOR XML PATH('') ),1,2,' ') UNION SELECT Belt=STUFF(( SELECT ', ' + CAST(ID AS VARCHAR) FROM ( SELECT ROW_NUMBER() OVER(ORDER BY ID) AS Number,ID FROM inserted ) AS a WHERE a.Number IN (@C) FOR XML PATH('') ),1,2,' ') UNION SELECT Belt=STUFF(( SELECT ', ' + CAST(ID AS VARCHAR) FROM ( SELECT ROW_NUMBER() OVER(ORDER BY ID) AS Number,ID FROM inserted ) AS a WHERE a.Number IN (@A,@B) FOR XML PATH('') ),1,2,' ') UNION SELECT Belt=STUFF(( SELECT ', ' + CAST(ID AS VARCHAR) FROM ( SELECT ROW_NUMBER() OVER(ORDER BY ID) AS Number,ID FROM inserted ) AS a WHERE a.Number IN (@B,@C) FOR XML PATH('') ),1,2,' ') UNION SELECT Belt=STUFF(( SELECT ', ' + CAST(ID AS VARCHAR) FROM ( SELECT ROW_NUMBER() OVER(ORDER BY ID) AS Number,ID FROM inserted ) AS a WHERE a.Number IN (@A,@C) FOR XML PATH('') ),1,2,' ') UNION SELECT Belt=STUFF(( SELECT ', ' + CAST(ID AS VARCHAR) FROM ( SELECT ROW_NUMBER() OVER(ORDER BY ID) AS Number,ID FROM inserted ) AS a WHERE a.Number IN (@A,@B,@C) FOR XML PATH('') ),1,2,' ') ) AS T end;This code incorrectly inserted data in order.How to insert data in order?In this moment my data is wrong inserted by order by? |
|