November 16, 2007 at 9:19 am
I am new to sql and currently using transact sql in a sql server 2005 environment. My dilemma is I am trying to figure out code to pull customers that were on prior plans.
I need to determine the following:
Heres an example:
Please list customers that are currently on Plan C but they had to have had Plan A then Plan B in that order prior to enrolling into Plan C. If the prior 2 conditions are not met then the customers account would not be in the final results of the Query.
November 16, 2007 at 10:59 am
In order to really provide an answer, a lot more detail would be needed regarding what the data structure looks like. It could be something as simple as providing an ORDER BY statement based on the plan name or it could be some kind of complicated subquery or cross apply or who knows what.
When you have a question, showing a bit of a structure (please, no trade secrets) and some of the TSQL that you have already tried is the best way to get help.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
November 16, 2007 at 3:51 pm
I agree with Grant. You definatly need to provide some more information but here is a very general response
[Quote]
Please list customers that are currently on Plan C but they had to have had Plan A then Plan B in that order prior to enrolling into Plan C. If the prior 2 conditions are not met then the customers account would not be in the final results of the Query.
[/Quote]
[Code]
SELECT * FROM Table1
WHERE PlanC_EndDate IS NULL AND PlanC_StartDate IS NOT NULL
AND PlanA_EndDate IS NOT NULL AND PlanA_StartDate IS NOT NULL
AND PlanB_EndDate IS NOT NULL AND PlanB_StartDate IS NOT NULL
AND PlanA_EndDate < PlanB_EndDate
[/Code]
This is where we could really use some kind of table schema to work from. This query makes A LOT of assumptions about your schema.
Kenneth FisherI was once offered a wizards hat but it got in the way of my dunce cap.--------------------------------------------------------------------------------For better, quicker answers on T-SQL questions, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/[/url]For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/[/url]Link to my Blog Post --> www.SQLStudies.com[/url]
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply