被大家取笑了!
别人写了个存储过程如下:
CREATE PROCEDURE proc_lkstmo AS
-----------删除表-----------------
if exists(select * from tempdb..sysobjects where name='##fo1')
drop table ##fo1
----------------纵转横-------------------
declare @s varchar(8000)
set @s=',[max]=max(level),[cod]=sum(case item when 314 then itemvalue else 0 end),[sd]=sum(case item when 464 then itemvalue else 0 end),[tn]=sum(case item when 466 then itemvalue else 0 end),[tp]=sum(case item when 652 then itemvalue else 0 end),[chla]=sum(case item when 501 then itemvalue else 0 end) '
select @s=@s+',[a'+convert(varchar(100),item)+']=max(case item when '''+convert(varchar(100),item)+''' then convert(varchar(100),level) else '''' end)' from(select distinct item from bsitem) a
exec(' select id=identity(int,0,1),stcode,month,lkname,lkfacename,lkco,lkfaceco,year'+@s+' into ##fo1 from view_1  group by stcode,month,lkname,lkfacename,lkco,lkfaceco,year')
declare @t varchar(8000)
--------------统计列名---------------
set @t='select *,('
select @t=@t+'(case when a'+convert(varchar(10),item)+'>estkind then '''+name+''' else '''' end)+' from(select distinct item,name from bsitem) a
select @t=substring(@t,1,len(@t)-1)+') as ''out'' from '
declare @sql varchar(8000)
-----------生成SQL语句---------------------
set @sql='SELECT c.*, dbo.LkFacebs.Estkind AS Estkind from
(SELECT *, CASE WHEN amn < 30 THEN ''Oligotropher'' WHEN amn >= 30 AND 
      amn <= 50 THEN ''Mesotropher'' WHEN amn > 50 AND 
      amn <= 60 THEN ''light'' WHEN amn > 60 AND 
      amn <= 70 THEN ''Middle'' WHEN amn > 70 THEN ''Hyper'' END AS ''std''
FROM (select *, ((CASE WHEN chla =0 
              THEN 0 ELSE 10 * (2.5 + 1.086 * log (chla)) END) 
              * 0.266 + (CASE WHEN tp =0.0
              THEN 0 ELSE 10 * (9.436 + 1.624 * log (tp)) END) 
              * 0.188 + (CASE WHEN tn =0.0
              THEN 0 ELSE 10 * (5.453 + 1.694 * log (tn)) END) 
              * 0.179 + (CASE WHEN sd =0.0
              THEN 0 ELSE 10 * (5.118 + 1.94 * log (sd)) END) 
              * 0.183 + (CASE WHEN cod =0.0
              THEN 0 ELSE 10 * (0.109 + 2.661 * log (cod)) END) * 0.183) AS ''amn''
 from ##fo1 a) b)c INNER JOIN LkFacebs
ON c.lkfaceco = dbo.LkFacebs.LkFaceCo AND 
       c.lkco =dbo.LkFacebs.LkCo'
exec(@t+'('+@sql+') q' )
GO我在查询分析器中调试得到了,一个结果集,是所有记录的结果集,现在我要把对所有记录的进行有条件查询,如“2003年11月”,那么我如何以参数的形式传入我的查询条件那?
不知道大家懂了没有,本人刚刚使用存储过程!