如果我在一个存储过程中写多个操作的话,@type作为判断,
CREATE PROC awot_fcl1
@type
AS
if @type=1
BEGIN SELECT distinct pPeriod FROM awot_fcl group by pPeriod order by pPeriod descENDif @type=2
BEGIN SELECT distinct name FROM awot_fcl group by name
END如果不带判断的调用为:
sql=exec awot_fcl1
如果带判断的又如何调用呢?
CREATE PROC awot_fcl1
@type
AS
if @type=1
BEGIN SELECT distinct pPeriod FROM awot_fcl group by pPeriod order by pPeriod descENDif @type=2
BEGIN SELECT distinct name FROM awot_fcl group by name
END如果不带判断的调用为:
sql=exec awot_fcl1
如果带判断的又如何调用呢?
或者
exec awot_fcl1 1
CREATE PROC awot_fcl1
@type int
AS
if @type=1
BEGIN SELECT distinct pPeriod FROM awot_fcl group by pPeriod order by pPeriod descENDif @type=2
BEGIN SELECT distinct name FROM awot_fcl group by name
END
CREATE PROC awot_fcl1
@type int
AS
BEGIN
if @type=1
SELECT distinct pPeriod FROM awot_fcl group by pPeriod order by pPeriod desc
if @type=2
SELECT distinct name FROM awot_fcl group by name
END
这样的写法还是不行的,
To:DBA_Huangzj
是报错,如果是没数据还好一些,
CREATE PROC awot_fcl1
@type int,
@yr_dsp datetime,
@fmonth datetime
AS
if @type =1
BEGIN
SELECT distinct pPeriod FROM awot_fcl where year(pPeriod)=@yr_dsp group by pPeriod order by pPeriod descENDif @type =2
BEGIN select isnull(sum(teu),0) as t1 from awot_fcl WHERE year(pPeriod)=@yr_dsp and month(pPeriod)=@fmonth
END调用时:
exec awot_fcl1 @type=1 “yr_dsp”
没有数据
exec awot_fcl1 1,'2013-01-01','2013-02-01'