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, August 27, 2014 9:28 AM
Points: 48, Visits: 273
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


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Yesterday @ 10:17 PM
Points: 17,817, Visits: 15,744
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, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Post #1538412
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse