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 |
|
udaymahajan
Starting Member
17 Posts |
Posted - 2008-10-24 : 08:09:56
|
| my sql query as followsdeclare @AdGroupID intdeclare @LastRowNo intset @AdGroupID=2set @LastRowNo=0SELECT ROW_NUMBER() OVER(ORDER BY [Advertisement].AdID) AS ROW, [Advertisement].AdID,AdSectionID,AdName,AdTypeFROM [Advertisement] LEFT JOIN [AdGroupDetails] ON [Advertisement].AdID = [AdGroupDetails].AdIDwhere [AdGroupDetails].AdGroupID = @AdGroupIDwhen i run records i getting records as followsROW AdID AdSectionID AdName AdType1 6 1 food G2 13 1 Jobs F3 14 1 Educational Fnow i want records as follows for exwhen i pass two parameters to above query as @AdGroupID and @LastRowNohaving values @AdGroupID=2 and @LastRowNo=0then i want display only first records likeROW AdID AdSectionID AdName AdType1 6 1 food Galso next when i pass two parameters to this query as @AdGroupID and @LastRowNohaving values @AdGroupID=2 and @LastRowNo=1then i want display only first records likeROW AdID AdSectionID AdName AdType2 13 1 Jobs Falso when when i pass two parameters to this query as @AdGroupID and @LastRowNohaving values @AdGroupID=2 and @LastRowNo=2then i want display only first records likeROW AdID AdSectionID AdName AdType3 14 1 Educational Fie i want to show subrecords one by one as per requirementso how can i design sql query to show recordsuday |
|
|
darkdusky
Aged Yak Warrior
591 Posts |
Posted - 2008-10-24 : 09:12:07
|
| Put select into derived table then use normal WHERE statement to return the row you wantdeclare @AdGroupID intdeclare @LastRowNo intset @AdGroupID=2set @LastRowNo=0select *from(SELECT ROW_NUMBER() OVER(ORDER BY [Advertisement].AdID) AS ROW,[Advertisement].AdID,AdSectionID,AdName,AdTypeFROM [Advertisement] LEFT JOIN [AdGroupDetails] ON [Advertisement].AdID = [AdGroupDetails].AdIDwhere [AdGroupDetails].AdGroupID = @AdGroupID) as awhere Row = @LastRowNo + 1 |
 |
|
|
|
|
|