| | |
Crazy CrossTab problems
Please support our MS SQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Dec 2008
Posts: 9
Reputation:
Solved Threads: 0
Here the solution that I got from another forum:
MS SQL Syntax (Toggle Plain Text)
SELECT ROW_NUMBER() OVER (PARTITION BY workID ORDER BY machineID) AS Seq,* INTO #Temp FROM TABLE DECLARE @MachineList varchar(1000),@Sql varchar(max) SELECT @MachineList= LEFT(ml.MacList,LEN(ml.MacList)-1) FROM (SELECT DISTINCT CAST(Seq AS varchar(10)) + ',' FROM #Temp FOR XML PATH('') )ml(MacList) SET @Sql='SELECT * FROM (SELECT * FROM #Temp )t PIVOT (SUM(hours) FOR Seq IN (['+ REPLACE(@MachineList,',','],[') + ']))p' EXEC(@Sql) DROP TABLE #Temp
![]() |
Other Threads in the MS SQL Forum
- Previous Thread: Need help in getting Average using SQL Cross Tab
- Next Thread: Get last month from timestamp
Views: 1065 | Replies: 10
| Thread Tools | Search this Thread |
Tag cloud for MS SQL
"last age autogrowth business connectingtodatabaseinuse count cursor data database dateadd datediff datepart day" dbsize deadlock delete_trigger exploit getdate hack highperformancecomputing hpc hpcserver2008 ibm iis limit live loop maximum microsoft ms mssql multiple multithreading news number password permission position query reporting result security server services sets single source sql sql-injection sqlserver sqlserver2005 subtype supercomputing supertype tables uniqueid update view weekday





