SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 help with formatting query result
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

victorp
Starting Member

1 Posts

Posted - 04/03/2009 :  03:59:50  Show Profile  Reply with Quote
hello all,
i have table having col 'code' and 'detail'
------------
code|detail.
------------
4.....|victor
4.....|18
5.....|macy.
5.....|24

how do i display the same info as
----------------
code|detail|age
----------------
4.....|victor|18
5.....|macy.|24

please help with the query..

regards

CtrlAltPhreak
Starting Member

3 Posts

Posted - 04/03/2009 :  04:51:25  Show Profile  Reply with Quote
Why do you not just have an age column in the table?
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22744 Posts

Posted - 04/03/2009 :  05:06:04  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
quote:
Originally posted by victorp

hello all,
i have table having col 'code' and 'detail'
------------
code|detail.
------------
4.....|victor
4.....|18
5.....|macy.
5.....|24

how do i display the same info as
----------------
code|detail|age
----------------
4.....|victor|18
5.....|macy.|24

please help with the query..

regards




Are the data coming from other sources or part of the table you have?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

bklr
Flowing Fount of Yak Knowledge

India
1693 Posts

Posted - 04/03/2009 :  06:29:19  Show Profile  Reply with Quote
is this u want check this once
declare @tab table(code int,detail varchar(32))
insert into @tab select 4,'victor'
insert into @tab select 4,'18'
insert into @tab select 5,'macy'
insert into @tab select 5,'24'

select code,
max(case when code = 4 then detail
when code = 5 then detail end) as name,
min(case when code = 4 then detail
when code = 5 then detail end) as age
from @tab
group by code
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.17 seconds. Powered By: Snitz Forums 2000