Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

status on a given date or date range Expand / Collapse
Author
Message
Posted Thursday, March 21, 2013 7:49 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 1:47 PM
Points: 23,081, Visits: 31,612
Sean Lange (3/21/2013)
Lynn Pettis (3/21/2013)
Sean Lange (3/21/2013)
Lynn Pettis (3/20/2013)
Sean Lange (3/20/2013)
I think that the above would miss Claim 7149 which as I read your issue should show up on the list. This is easy enough to correct by changing @StatusDate to a datetime and the where clause to StatusDate <= @StatusDate


Actually, Sean, my code works as is. If you change the value in @StatusCode from 300 to 210 it catches Claim 7149 just fine.

If you look closely, I cast the Datetime column to a date value (this is SQL Server 2008) and do a <+. Else wise you need to add 1 day to the date you are using, for 2013-03-14 you would want < '2013-03-15' if looking at the full datetime value in StatusDate.


Lynn, claim 7149 was in a status of 300 until 00:35:50.000 on 2013-03-14 and the code you posted does not return it.


Based on the OP's original post the status changed on that date from 300 to 310, so this record would not be shown. His requirement simply specified that on a given date was a claim still in a given state, not if it had been in that state. The claim changed state on that date.


Let's say I need a query that would tell me which claims were at a status of 300 on 3/14/2013. Some of these claims were, in fact, at a status of 300 on that day but how do I query that since there is no entry for the specific date of 3/14/2013? ( ie: claim 7148 was changed to a status of 300 on 3/10 and was not changed to another status until 3/20, so I would need that claim pulled back in my query as it would have still been status 300 on 3/14.)



Nothing above indicated that he wanted to see those claims that changed status on that date from 300, but that were still in a status of 300 on a given date and had not changed yet. Nothing indicates that time is relevant to the query.

Trust me, if time had been relevant to the query I would have accounted for it.


I guess that comes down to interpretation and what the OP wants. It did have a status of 300 on that day, for at least part of it. I was trying to point out a possible issue depending on what the OP needs. It seems to me that the claim in question should show up for that day with a status of either 300 or 310 because it did in fact have both of those values on that day.



The only example provided by the OP was Claim 7148, so I based my assumptions on that. I guess it would have been better had the OP provided an explicit representation of expected results based on the sample data.



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1433793
Posted Thursday, March 21, 2013 7:55 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 1:47 PM
Points: 23,081, Visits: 31,612
Also, based on the phrasing of the question, it looks like a query against historical data. If all statuses were to be returned it could have been interpreted as show the most current status (or last status) on a given date.

I did sort the data in descending order for a given claim by the complete date/time value which would put the most current status at the top of the list.



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1433796
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse