Reply to Re: dynamically trasnpose rows into columns

Your name:

Reply:


Posted by jsfromynr on 12/23/05 13:15

Hi There,

Try this It might help you.
Create View vwtmpData1
As
Select 1 DeviceID ,'color' FieldName,'red ' FieldValue
Union All
Select 1,'shape','square'
Union All
Select 1,'Weight(kg)','2.0'
Union All
Select 2,'shape','round'
Union All
Select 2,'Weight(kg)','1.5'
Union All
Select 3,'color','blue'
Union All
Select 3,'shape','oval'
Union All
Select 3,'Weight(kg)','1.0'


Go



Declare @sql varchar(2000)
Set @sql = 'Select DeviceID '
Select @sql = @sql + ', Max( Case When FieldName = '''+FieldName +'''
Then FieldValue End) As [' + FieldName +']' + char(13) + char(10)
>From vwTmpData1 Group By FieldName
Set @sql = @sql + ' From vwTmpData1 Group By DeviceId'
Print @sql
Exec(@sql)

All said and done !! Still knowing the number of columns is good
insight in the bussiness needs of the client . What you are trying to
acheive is EAV (Entity Attribute Value), which is not so good. Just
think how much time it will waste to write a complex query.

With Warm regards
Jatinder Singh

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация