因为sql语句很庞大,都是用union连接的,所以我需要的sql语句中选择的条件格式是这样的
...num as areaname1,' as areaname2,' as areaname3,' as areaname4,' as areaname5... union ...' as areaname1,num as areaname2,' as areaname3,' as areaname4,' as areaname5... union ...' as areaname1,' as areaname2,num as areaname3,' as areaname4,' as areaname5... union ...' as areaname1,' as areaname2,' as areaname3,num as areaname4,' as areaname5... union ...' as areaname1,' as areaname2,' as areaname3,' as areaname4,num as areaname5...
以上看到了,就是每个列都要循环一遍,并且num的位置是变化的.
这是我声明的游标:
declare _cursor CURSOR forward_only FOR--声明游标 select areacode,areaname from #temp DECLARE @areacode varchar(20)--游标变量 declare @areaname varchar(20)--游标变量
现在就是要将由表中的areaname都要循环一遍拼成选择条件,然后num位置也要变化。
付费偷看金额在0.1-10元之间
一周热门 更多>