Where 子句 SQL Server 2008 中的案例查询

Case Query in Where Clause SQL Server 2008

我有以下 SQL 查询(我知道它可能非常丑陋且效率低下)。我需要能够查询

的位置
IF @techID = 0   
Then Technician.Tech_ID > 0
Else @TechID <> 0
Then Technician.Tech_ID = @TechID

我有点不知道如何完成这个

sql = "Select Long_Call.Department,Technician.First_Name,Technician.Last_Name, Clinic_ID,Long_Call.Case_Number,Long_Call.Synopsis," +
                           "Long_Call.Version,Long_Call.Time_On_Call, RIGHT(CONVERT(VARCHAR,Long_Call.Call_DateTime,100),7) as Call_Time,CONVERT(VARCHAR(10),cast(Long_Call.Call_DateTime as date),101) as Call_Date,"+
                           "Call_Tracking.Description as Description from Long_Call,Call_Tracking, " +
                           "Technician where Long_Call.Tech_ID = Technician.Tech_ID and Long_Call.Tracking_ID = Call_Tracking.Tracking_ID and CAST(Long_Call.Call_DateTime as Date)"+
                           "BETWEEN @StartDate and @EndDate and Long_Call.Time_On_Call >= @Call_Length and Technician.Tech_ID = @TechID and Long_Call.Tracking_ID <> 2 and Long_Call.Tracking_ID <> 3;";

你可以尝试使用复合条件

WHERE (@techID = 0 AND Technician.Tech_ID > 0)
OR Technician.Tech_ID = @TechID;