有个smalldatetime类型的数据QuitTime,一开始不给他赋值,自动变为NULL
可后面一个存储过程用到他的时候  
where QuitTime=NULL 这个条件却不起作用,问一下兄弟们怎么回事喔..

解决方案 »

  1.   

    where   QuitTime is NULL
      

  2.   

    恩.null值不能用=
    只能is null进行判断
      

  3.   


    或者:where isnull(QuitTime,'')=''
      

  4.   

    那比较日期大小也不能用>和<号么??
      

  5.   

    那判断日期大小也能用>号和<号咯?
      

  6.   

    isnull(QuitTime,'') >或<
    或者
    isnull(QuitTime,'') between ... and...
      

  7.   

    where (QuitTime IS NULL)
      

  8.   

    create proc RZ_percent
    @T1 smalldatetime,@T2 smalldatetime,@RT1 varchar(8)
    as
    begin
    declare @TS1 smallint
    declare @TS2 smallint
    declare @TS smallint
    declare @FJS smallint
    declare @SJDTS smallint
    declare @PS float
    select @TS1=sum(((year(@T2)-year(FisrtTime))*365+(month(@T2)-month(FisrtTime))*30+(day(@T2)-day(FisrtTime)))) from Guest
    where FisrtTime>=@T1 and QuitTime is NULL and RoomID in (select RoomID from RoomInfo 
    where RoomType=@RT1)
    select @TS2=sum(((year(QuitTime)-year(FisrtTime))*365+(month(QuitTime)-month(FisrtTime))*30+(day(QuitTime)-day(FisrtTime)))) from Guest
    where FisrtTime>=@T1 and QuitTime<=@T2 and RoomID in (select RoomID from RoomInfo 
    where RoomType=@RT1)
    Set @TS=@TS1+@TS2
    select @FJS=count(RoomID) from RoomInfo where RoomType=@RT1
    set @SJDTS=((year(@T2)-year(@T1))*365+(month(@T2)-month(@T1))*30+(day(@T2)-day(@T1)))
    set @PS=(@TS/@SJDTS)/@FJS
    print '(入住率为:'+cast(@PS1 as varchar(10))+')'
    end
    就是这个东东了  结果总是输出一片空白 是不是判断条件出语法错误了  可却没报错  
    估计是smalldatetime那些数据出问题了吧  朋友们帮我看看啊,,
      

  9.   

    where       QuitTime   is   NULL
    1楼说的对
      

  10.   

    where QuitTime is NULL
      

  11.   

    而且print   '(入住率为:'+cast(@PS1   as   varchar(10))+')' 这句没有这个变量@PS1
      

  12.   

    判断用 is null,赋值用=null