December 29, 2011 at 2:46 pm
Hello all,
I am having issue with this query
use ERCOT
SELECT
sp.station_code
,sp.load_zone
,ccs.LOAD_TYPE_DESC
,tdspx.esiid
,ccs.esiid
,tdspx.address
,ccs.flow_end_date
,ccs.flow_START_DATE
,ccs.account_number
FROM esg.dbo.clean_cust_account_lcd_cancel_switch ccs
left outer join dbo.all_tdsp_extracts tdspx on ccs.esiid = tdspx.esiid
left outer join (select distinct station_code, load_zone from dbo.Settlement_Points) sp on sp.station_code = tdspx.station_code
where flow_START_DATE is not null and flow_START_DATE < '2012-01-03'
and flow_end_date is null or flow_end_date > '2012-01-03'
I am not getting the correct number of records. Is there any mistake in the where clause?
Please assist.
Thanks
December 29, 2011 at 3:00 pm
where flow_START_DATE is not null and flow_START_DATE < '2012-01-03'
and flow_end_date is null or flow_end_date > '2012-01-03'
I'd suggest adding some parens to the where - change to :
where
(flow_START_DATE is not null and flow_START_DATE < '2012-01-03')
and (flow_end_date is null or flow_end_date > '2012-01-03')
December 29, 2011 at 3:01 pm
I tried this. But not working
December 29, 2011 at 3:01 pm
Use brackets to group your "and" and "or" conditions correctly. Right now it's going to return everything with the end date greater than the date specified regardless of the start since there is an "or" with no brackets. Also, if a date is less than X, it already cannot be null so you might as well remove that condition.
December 29, 2011 at 3:11 pm
If adding the parenthesis as suggested is still not providing the accurate number of records, please post sample data and structures so we can recreate and test.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply