Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
abbikhan
Starting Member
26 Posts |
Posted - 2011-05-03 : 06:40:57
|
I want to retrieve data in this manner but how can and what statements should I use, I am struckSetp1: Having 4 variables@StartDate=’9/9/2010’, @EndDate=’9/9/2011’, @StartingStage=1, @EndingStage=5And another which have values @count =2, 3, 4, 5 (if @ StartingStage=1 and @EndingStage=5) Step2: (SELECT id FROM Table1WHERE Stage=@StartingStage--(=1)AND Date BETWEEN @StartDate AND @EndDate) A_Result_setStep3:(SELECT id FROM Table1 inner join with A_Result_setWHERE Stage=@count--(=2)AND Date BETWEEN @StartDate AND @EndDate) new_resultset1Step 3:(SELECT id FROM Table1 inner join with new_resultset1WHERE Stage=@count--(=3)AND Date BETWEEN @StartDate AND @EndDate) new_resultset2Step4:(SELECT id FROM Table1 inner join with new_resultset2WHERE Stage=@count(--=4)AND Date BETWEEN @StartDate AND @EndDate) new_resultset3Step5:(SELECT id FROM Table1 inner join with new_resultset3WHERE Stage=@count(--=5)AND Date BETWEEN @StartDate AND @EndDate) new_resultset4Result = new_resultset4 |
|
raghuveer125
Constraint Violating Yak Guru
285 Posts |
Posted - 2011-05-03 : 06:48:46
|
What result you want? Post some output.And send your full queryIn Love... With Me! |
 |
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-05-03 : 06:54:11
|
Do you have rows for each id with a stage from 1 to 5 and you want to get the IDs with entries for each stage up to the count entered? I doubt it but...select idfrom Table1where Date BETWEEN @StartDate AND @EndDateand stage betwen @StartingStage and @EndingStagegroup by idhaving count(*) = @EndingStage-@StartingStage+1==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
abbikhan
Starting Member
26 Posts |
Posted - 2011-05-03 : 07:57:22
|
quote: Originally posted by nigelrivett Do you have rows for each id with a stage from 1 to 5 and you want to get the IDs with entries for each stage up to the count entered? I doubt it but...select idfrom Table1where Date BETWEEN @StartDate AND @EndDateand stage betwen @StartingStage and @EndingStagegroup by idhaving count(*) = @EndingStage-@StartingStage+1Yes i have rows in table 2 agianst these idsand that should not be between two stages, that should complete these stages one by one then may be some ids removed
|
 |
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-05-03 : 08:39:40
|
Not sure what you want to do with this.Try explaining in english rather than code.Sounds like you have a table with an entry for each stage that is completed by an id and some entries can be removed later.You pass in a start and end date and a start stage and end stage.What is the resultset you want from this?==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|