June 10, 2009 at 6:12 am
hi All
i Have The Table Structure Like This
DECLARE @tblLinks TABLE
(
LinkID BIGINT,
StartDate DateTime,
EndDate DateTime,
PhaseType int
)
insert @tblLinks
select 100,GetDate()-3,GetDate()-2,1
insert @tblLinks
select 100,GetDate()-2,GetDate()-1,2
insert @tblLinks
select 100,GetDate()-1,null,3
select * from @tblLinks -- this is From Table
-- Required output
-- I Need output Like this
Select 100 LinkID,1 PhaseType1,GetDate()-3 Phase1StartDate,GetDate()-2 Phase1EndDate,
2 PhaseType2,GetDate()-2 Phase2StartDate,GetDate()-1 Phase2EndDate,
3 PhaseType3,GetDate()-1 Phase3StartDate
Please Help me
Thanks
Deepak.a
June 10, 2009 at 6:53 pm
Hi,
I'm not sure what your desired output is but you could try the following:
select a.LinkID, a.PhaseType, a.StartDate, a.EndDate, b.PhaseType, b.StartDate, b.EndDate, c.PhaseType, c.StartDate
from @tblLinks a inner join @tblLinks b on a.linkID = b.linkID and a.PhaseType=1 and b.phaseType=2 inner join @tblLinks c on b.linkID = c.linkID and c.PhaseType=3
This code joins the same table three times based on the linkID and the phase types.
If that is not what you are after then please explain further.
Bevan Keighley
June 10, 2009 at 9:59 pm
Hi
Thanks For u r Reply ur Query is working For me 🙂
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply