我有下面的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;";发布于 2015-08-31 20:14:03
您可以这样做,使用复合条件。
WHERE (@techID = 0 AND Technician.Tech_ID > 0)
OR Technician.Tech_ID = @TechID;https://stackoverflow.com/questions/32319109
复制相似问题