我需要在 sql 中獲取 alldata whereclause? (i need to get alldata whereclause in sql?)


問題描述

我需要在 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 PenguenKM.PenguenDForck42)

參考文件

  1. i need to get alldata whereclause in sql? (CC BY‑SA 3.0/4.0)

#sql-server-2005 #SQL #sql-server






相關問題

可更新查詢所需的最低權限 (Access Project) (Minimum permissions required for an updatable query (Access Project))

Sql中的WHERE,結合兩個快速條件會成倍增加成本 (WHERE in Sql, combining two fast conditions multiplies costs many times)

是否可以重構此語句以刪除子查詢? (Is it possible to refactor this statement to remove the subquery?)

Không gửi được tệp nhật ký bằng 'Tác vụ Gửi Thư' từ trình xử lý OnError (Sending the log file using a 'Send Mail Task' from the OnError handler fails)

擴展 SSRS 中的圖表功能 (Extending chart functionality in SSRS)

sql server 2005 數據庫郵件錯誤(操作已超時) (sql server 2005 database mail error (The operation has timed out))

從.NET應用程序到SQL Server的緩慢調用 (Sporadically Slow Calls From .NET Application To SQL Server)

我需要在 sql 中獲取 alldata whereclause? (i need to get alldata whereclause in sql?)

一種檢查 SQL 2005 中是否存在外鍵的方法 (A way to check if foreign key exists in SQL 2005)

如何在 SSIS 中調用存儲過程? (How do you call a Stored Procedure in SSIS?)

什麼會使桌子“變慢”? (What would make a table "slow?")

可以在這裡使用 Common Table 表達式來提高性能嗎? (Can Common Table expressions be used here for performance?)







留言討論