sql server - Simplify T-SQL Query -
i simplify query if possible.
select max(tdatetimeofsurvey) stocks.dbo.tblsurvey ( (select isnull(sum(twettons), 0) stocks.dbo.tblsurvey tstockareaid = 3 , tdatetimeofsurvey between '20140201' , '20140228') + (select isnull(sum(twettons), 0) stocks.dbo.tblsurvey tstockareaid = 103 , tdatetimeofsurvey between '20140201' , '20140228') + (select isnull(sum(twettons), 0) stocks.dbo.tblsurvey tstockareaid = 181 , tdatetimeofsurvey between '20140201' , '20140228') ) > 0 , tstockareaid in (3,103,181) -- ras, soil, dorb , tdatetimeofsurvey between '20140201' , '20140228'
many thanks, pierre
please try:
select max(tdatetimeofsurvey) stocks.dbo.tblsurvey tstockareaid in (3,103,181) , tdatetimeofsurvey between '20140201' , '20140228' having sum(twettons)>0
Comments
Post a Comment