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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

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

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 creating new table with ref to old
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sqlberry
Starting Member

6 Posts

Posted - 07/22/2013 :  01:38:08  Show Profile  Reply with Quote
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)

Singapore
17689 Posts

Posted - 07/22/2013 :  02:24:15  Show Profile  Reply with Quote

select	*
from	tbl t
	pivot
	(
		max(Col1) for
		Col2 in ([A], [B])
	) p



KH
Time is always against us

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 07/22/2013 :  02:39:49  Show Profile  Reply with Quote

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


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

sqlberry
Starting Member

6 Posts

Posted - 07/22/2013 :  08:46:18  Show Profile  Reply with Quote
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

India
52326 Posts

Posted - 07/22/2013 :  10:04:56  Show Profile  Reply with Quote
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 - 07/22/2013 :  11:39:03  Show Profile  Reply with Quote
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

India
52326 Posts

Posted - 07/22/2013 :  11:54:25  Show Profile  Reply with Quote
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
  Previous Topic Topic Next 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.02 seconds. Powered By: Snitz Forums 2000