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 2008 Forums
 Transact-SQL (2008)
 creating new table with ref to old

Author  Topic 

sqlberry
Starting Member

6 Posts

Posted - 2013-07-22 : 01:38:08
I need to create a new table with reference to an old table.
the following link has table data sample in Excel.

http://s1315.photobucket.com/user/blueberry20137/media/SQLreq_zps6879a770.png.html?sort=3&o=0

Can anyone help??
TIA

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2013-07-22 : 02:24:15
[code]
select *
from tbl t
pivot
(
max(Col1) for
Col2 in ([A], [B])
) p
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-07-22 : 02:39:49
[code]
SELECT MAX(CASE WHEN Col2 = 'A' THEN Col1 END) AS ColA,
MAX(CASE WHEN Col2 = 'B' THEN Col1 END) AS ColB,
Col3
FROM tbl
GROUP BY Col3
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

sqlberry
Starting Member

6 Posts

Posted - 2013-07-22 : 08:46:18
quote:
Originally posted by visakh16


SELECT MAX(CASE WHEN Col2 = 'A' THEN Col1 END) AS ColA,
MAX(CASE WHEN Col2 = 'B' THEN Col1 END) AS ColB,
Col3
FROM tbl
GROUP BY Col3


Thank you so much. God Bless you.
------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-07-22 : 10:04:56
you're welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

sqlberry
Starting Member

6 Posts

Posted - 2013-07-22 : 11:39:03
quote:
Originally posted by visakh16

you're welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs




Will you help me in this one too?

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=186996
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-07-22 : 11:54:25
quote:
Originally posted by sqlberry

quote:
Originally posted by visakh16

you're welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs




Will you help me in this one too?

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=186996


Done

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -