Using SQL Server 2000
Table1
ID
A001
A002
A003
A004
A005
A006
A007
....
....
A028
From the above table, i want to split the 3 rows into 3 column, order by id
Rows display like this
Expected Output
id1 id2 id3
A001 A002 A003
A004 A005 A006
A007 A008 A009
...
...
A025 A026 A027
A028 null null
ID is not fixed, id may contain like this also (01A or A001 or 1A1 or etc....)
Table 1 row count is not fixed, it may goes more than 100 rows also. Column 3 is fixed. How to make a query for the above condition.
Need Query Help
I would do it as follows:
Awith nothing in those IDs and convert them to integersSELECTstatements where the condition will be integer ID calculated in above step %3 is 1, 2, 0 respectively, to yield the records in each row.ROW_NUMBER()would have been handy, but since you are on SQL Server 2000, you would useIDENTITY(INT, 1, 1)to generate row numbers for each row in these SELECT statements and JOIN on this value.But since
IDENTITYcan be used inSELECTonly withINTOclause, you would end up with temporary tables that contain each column and join on them.If you were on SQL Server 2005 or higher, all this could have been done in a single query as follows: