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)
 Query Help - Table 1 to Table 2

Author  Topic 

kenlok
Starting Member

16 Posts

Posted - 2009-10-08 : 03:29:17
How can I make it from Table 1 to Table 2

Thanks

<The Size[1-8] is order by SizeSeq>

Table 1
JobNo FabricTrim MatDetId SizeSeq SizeSpec
112233 1 2 1 S
112233 1 2 2 M
112233 1 2 3 L
112233 1 2 4 LL
112233 1 3 1 S
112233 1 3 2 M
112233 1 3 3 L
112233 1 3 4 LL


Tabe 2
JobNo FabricTrim MatDetId Size1 Size2 Size3 Size4 Size5 Size6 Size7 Size8
112233 1 2 S M L LL null null null null
112233 1 3 S M L LL null null null null

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-10-08 : 03:31:11
use PIVOT operator. Refer to Books online for syntax and further information


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

Go to Top of Page

kenlok
Starting Member

16 Posts

Posted - 2009-10-09 : 05:37:02
KH,

Thanks for your support, I search some book about PIVOT.
But I also dont know how to write it.

Would it be possible to give me some hits?

Thanks
Ken
Go to Top of Page

sanoj_av
Posting Yak Master

118 Posts

Posted - 2009-10-09 : 06:29:07
Create the procedure dynamic_pivot as per the following blog by madhivanan.
http://sqlblogcasts.com/blogs/madhivanan/archive/2008/08/27/dynamic-pivot-in-sql-server-2005.aspx

Then execute it as follows.
EXEC dynamic_pivot 'Select JobNo,FabricTrim,MatDetId,SizeSpec from Table1','SizeSeq','MIN(SizeSpec)'


Go to Top of Page
   

- Advertisement -