Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How to write a Query to get related result Expand / Collapse
Author
Message
Posted Wednesday, February 5, 2014 4:53 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, July 16, 2014 1:54 PM
Points: 46, Visits: 252
I need help to write a query like below oupt put.

create table #table (id int, cid int , startdate datetime)
insert #table

select 1, 100, '02/23/2014'
union select 1, 100, '06/25/2013'
union select 1, 100, '06/04/2013'
union select 1, 100, '06/17/2013'
union select 2, 200, '08/9/2013'
union select 2, 200, '08/3/2013'


First date 02/23/2014...So heere I need only the 2013 Current End dates Based On Start Date...

I need oupt put like below table based on above table.

id cid start_date end_date
1 100 02/23/2014 --
1 100 06/25/2013 12/31/2013
1 100 06/04/2013 06/24/2013
1 100 06/17/2013 06/03/2013
2 200 08/9/2013 12/31/2013
2 200 08/03/2013 08/08/2013

Thanks,
Post #1538408
Posted Wednesday, February 5, 2014 4:58 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 9:59 PM
Points: 21,297, Visits: 14,988
duplicate post, please post replies at this post instead http://www.sqlservercentral.com/Forums/Topic1538410-392-1.aspx



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #1538412
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse