question

lkv avatar image
lkv asked

how to combine two consecutive dates in different rows in a table

q1.jpg

Can anyone help me in combining the data in 1st set to the one in 2nd set. WID,LID are key columns in the set.

t-sqlsql server
q1.jpg (35.9 KiB)
q1.jpg (35.9 KiB)
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
anthony.green avatar image
anthony.green answered

What do you want as the output?

A data set of 9 rows? If so use a union

A set of matching data from both tables? (3 rows) use a INNER JOIN

A set of matching data from one table, and any matching data from the second? (6 rows with nulls) use an OUTER JOIN

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

lkv avatar image lkv commented ·

1st set of 6 records are from original table and script should combine records into bottom 3 records .

For each WID,LID if startdate of 2nd record is immediate date of previous enddate ,we need to merge those records into a single record

0 Likes 0 ·
anthony.green avatar image anthony.green lkv commented ·

Please post in a picture in excel or something what you want the output to look like

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.