select * from
(
select 代码 as stockCodeName , 日期 as date, Subject = '散户' , Result = 散户 from a20080324
union all
select 代码 as stockCodeName , 日期 as date, Subject = '中户' , Result = 中户 from a20080324
union all
select 代码 as stockCodeName , 日期 as date, Subject = '大户' , Result = 大户 from a20080324
union all
select 代码 as stockCodeName , 日期 as date, Subject = '法人' , Result = 法人 from a20080324
union all
select 代码 as stockCodeName , 日期 as date, Subject = '机构' , Result = 机构 from a20080324
union all
select 代码 as stockCodeName , 日期 as date, Subject = '散户' , Result = 散户 from a20080321
union all
select 代码 as stockCodeName , 日期 as date, Subject = '中户' , Result = 中户 from a20080321
union all
select 代码 as stockCodeName , 日期 as date, Subject = '大户' , Result = 大户 from a20080321
union all
select 代码 as stockCodeName , 日期 as date, Subject = '法人' , Result = 法人 from a20080321
union all
select 代码 as stockCodeName , 日期 as date, Subject = '机构' , Result = 机构 from a20080321
union all
select 代码 as stockCodeName , 日期 as date, Subject = '散户' , Result = 散户 from a20080320
union all
select 代码 as stockCodeName , 日期 as date, Subject = '中户' , Result = 中户 from a20080320
union all
select 代码 as stockCodeName , 日期 as date, Subject = '大户' , Result = 大户 from a20080320
union all
select 代码 as stockCodeName , 日期 as date, Subject = '法人' , Result = 法人 from a20080320
union all
select 代码 as stockCodeName , 日期 as date, Subject = '机构' , Result = 机构 from a20080320
...
...
...
) t
where stockcodename = '600000'
order by stockCodeName, date,
case Subject
when '散户' then 1
when '中户' then 2
when '大户' then 3
when '法人' then 4
when '机构' then 5
end a20080324是根据实际交易日生成的表,如何将以上这段语句写成存储过程,其中交易日的起始作为参数可以自行设定,同时where stockcodename = '600000'中的‘600000’也作为参数自行设定。
是指表名要作为参数传进来吗?那a20080320,a20080321等等也是传进来?
代码 as stockCodeName ,
日期 as date,
Subject = '散户' ,
Result = 散户
,row=1--子查询加多一列作为排序
from a20080320表名:只通过sysobjects where : stuff(Name,1,1,'') --取日期作为判断
动态生成语句..row=1--子查询加多一列作为排序 省了case when ....
case Subject
when '散户' then 1
when '中户' then 2
when '大户' then 3
when '法人' then 4
when '机构' then 5
end