我需要在sql中获取所有数据where子句?

时间:2009-05-15 13:53:22

标签: sql sql-server sql-server-2005

我需要获取所有数据,如果Page!= @ page,get AllDATA

选择计数(页面)为TARIH,
    (datepart(小时,日期)* 60 + datepart(分钟,日期))/ @ countgap作为SIRA
    来自scr_SecuristLog
    其中@ date1和@ date2之间的日期和Page = @ page或Page = AllDATA

3 个答案:

答案 0 :(得分:1)

尝试:

select
    count(page) as TARIH
        ,(datepart(hour,Date)*60+datepart(minute,Date))/@countgap as SIRA
    from scr_SecuristLog
    where Date between @date1 and @date2 and (Page=@page or Page = AllDATA)

答案 1 :(得分:0)

解决方案: 选择计数(页面)为TARIH,
    (datepart(小时,日期)* 60 + datepart(分钟,日期))/ @ countgap作为SIRA
    来自scr_SecuristLog
    其中@ date1和@ date2之间的日期和(Page = @ page或@ page ='TümKullanıcılar')

答案 2 :(得分:0)

select count(page) as TARIH,
(datepart(hour,Date)*60+datepart(minute,Date))/@countgap as SIRA
from scr_SecuristLog
where 
    Date between @date1 and @date2 
    and 
    (
        (@page is not null and Page=@page) 
        or (@page is null and @page=@page)
    )

将返回date1和date2之间的所有数据,并且只有等于参数的数据,或者如果参数为null,则返回date1和date2之间的所有数据