Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 help with formatting query result

Author  Topic 

victorp
Starting Member

1 Post

Posted - 2009-04-03 : 03:59:50
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 - 2009-04-03 : 04:51:25
Why do you not just have an age column in the table?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-03 : 05:06:04
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
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-04-03 : 06:29:19
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
   

- Advertisement -