問題描述
我需要在 sql 中獲取 alldata whereclause? (i need to get alldata whereclause in sql?)
i need to take all data if Page!=@page, get AllDATA
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:
try:
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)
方法 2:
Solution: 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='Tüm Kullanıcılar')
方法 3:
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)
)
will return all data between date1 and date2 and only data equal to the parameter, or if the parameter is null will return all data between date1 and date2
(by Penguen、KM.、Penguen、DForck42)