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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Need assistance with grouping query

Author  Topic 

chippyles
Yak Posting Veteran

68 Posts

Posted - 2006-06-12 : 14:21:39
I have this query that I will create into a stored procedure after this query is complete.

I have commented a line of code within this query. This line of code will insert the data that the query creates (Pretty much a grouped query of @Data). I need to take this query and JOIN the table that I need to INSERT the data into. I want the JOIN to eliminate the possibility of displaying duplicates.

How should this query look?

Thanks for your help!!


Declare @Data
Table (RowId Integer Identity(1,1),
tRSSQL_TRANS DateTime,
bEND_OF_REEL bit,
nLINE Integer
)

Insert Into @Data(tRSSQL_TRANS, bEND_OF_REEL, nLINE)
Select tRSSQL_TRANS, bEND_OF_REEL, nLINE
From vM_FR_STOPS_Grouping
Order By nLine, tRSSQL_TRANS

--Insert Into tM_FR_WIP_UnitID_FastStops(nLINE, StartGroup, EndGroup)

Select A.nLine,
A.StartGroup,
Min(D.tRSSQL_TRANS) As EndGroup
From (
Select B.tRSSQL_TRANS As StartGroup,
B.nLine
From @Data A
Inner Join @Data B
On A.RowId = B.RowId -1
And A.nLine = B.nLine
Where A.bEND_OF_REEL = 1
And B.bEND_OF_REEL = 0
) A
Inner Join @Data D
On A.nLine = D.nLine
And A.StartGroup < D.tRSSQL_TRANS
And D.bEND_OF_REEL = 1
Group By A.StartGroup, A.nLine

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-06-12 : 15:00:07
Duplicate:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=67663

Tara Kizer
aka tduggan
Go to Top of Page
   

- Advertisement -