不太明白LZ为什么要这样做,不过应该可以用这样的存储过程解决:
create procedure EQCheckPlanQuery
(
  @Plan_Date datetime,
  @EQContent varchar(50),
  @Check_Date datetime,
  @Principal int
)
asdeclare @Sql nvarchar(200)
set @Sql = 'select * from EQCheckPlan where 1 = 1'if @Plan_Date is not null
begin
  set @Sql = ' and Plan_Date = @Plan_Date'
endif @EQContent is not null
begin
  set @Sql = ' and EQContent = @Plan_Date'
endif @Check_Date is not null
begin
  set @Sql = ' and Check_Date = @Plan_Date'
endif @Principal is not null
begin
  set @Sql = ' and Principal = @Plan_Date'
endexecute sp_executeSQL @Sql

解决方案 »

  1.   

    select * from EQCheckPlan 
    where
    (Plan_Date is null or Plan_Date=@Plan_Date)
    and 
    EQContent is null or  EQContent =@EQContent ) 
    and
    (Check_Date is null or Check_Date =@Check_Date )
    and
    (Principal is null or Principal=@Principal)
      

  2.   

    怎么在执行的时候提示and附近有错误啊!
      

  3.   

    :问题可否在,datetime的格式上,你的日期变量,需要计算小时:分:秒吗?若只是年、月、日的话,其格式:YYYY-MM-DD,请再试一下。
      

  4.   

    to:zhaotianyi
    写法不妥,当不以某列为条件时,并不代表筛选该列为空的行.
    例如 Plan_Date is null or Plan_Date=@Plan_Date 这里可能写为 @Plan_Date is null or Plan_Date=@Plan_Date 才符合你的意思,不过是没有这样的语法的。
      

  5.   

    Scipio(西庇阿) 的对,支持