不好意思完整的是这样。
IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS
WHERE TABLE_NAME = 'pzview1')
DROP VIEW pzview1
GO
create view pzview1 as SELECT Sum(md) As JJe, Sum(mc) As DJe,iperiod, isignseq, ino_id FROM GL_accvouch
WHERE (1=1 and GL_accvouch.iperiod >=1 and GL_accvouch.iperiod <=12) GROUP BY iperiod,isignseq,ino_id
IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS
WHERE TABLE_NAME = 'pzview1')
DROP VIEW pzview1
GO
create view pzview1 as SELECT Sum(md) As JJe, Sum(mc) As DJe,iperiod, isignseq, ino_id FROM GL_accvouch
WHERE (1=1 and GL_accvouch.iperiod >=1 and GL_accvouch.iperiod <=12) GROUP BY iperiod,isignseq,ino_id
@wherestr = "1=1"
set @wherestr = @wherestr + " and xxx=@xxx"
set @wherestr = @wherestr + " and xxx=@xxx"
set @wherestr = @wherestr + " and xxx=@xxx"
那么如果没有1=1,就会有错误。
1=1 and 条件
select a.* from a left join b on a.编号 = b.编号 left join c on a.编号 = c.编号