ScenarioA table that contains several columns that you need to take and change into rows in order to normalize the data. With SQL Server 2005, a new T-SQL command UNPIVOT can help. An example table:
**Table called MyTableFieldID FieldOne FieldTwo FieldThree1 abc 3.40 2008-03-03 00:00:00.0002 def 4.00 2008-01-02 00:00:00.000
**Table DesignFieldID is an integerFieldOne is char(10) FieldTwo is decimal(14,2)FieldThree is a datetime
Sample CodeSELECT FieldId, FieldCode, FieldValueFROM ( SELECT FieldId, CONVERT(varchar(50), RTRIM(FieldOne )) AS FieldOne, CONVERT(varchar(50), FieldTwo) AS FieldTwo, CONVERT(varchar(50), FieldThree) AS FieldThree FROM SampleUnpivot) MyTableUNPIVOT(FieldValue FOR FieldCode IN (FieldOne, FieldTwo, FieldThree))AS MyUnPivot
Results
FieldID FieldCode FieldValue1 FieldOne abc1 FieldTwo 3.401 FieldThree Mar 3 2008 12:00AM2 FieldOne def2 FieldTwo 4.002 FieldThree Jan 2 2008 12:00AM
Notes