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.
Author |
Topic |
devizerosoft
Starting Member
2 Posts |
Posted - 2014-01-22 : 04:47:57
|
Please find the below code and help me to complete this query. Thanks for your help..1. Catch all unload events for a date range 2. Sequence the time events in numerical order incrementing by 1 3. Display the sequence in one column 4. Have another column for each unload serial number - start date and display all unload density values per sequence 5. The column creation for the serial numbers should be dynamic requiring looping 6. Create the script so that you can feed it a start date and end date */SET NOCOUNT ON;/*declare initial data holding table*/CREATE TABLE ##data (recorddatetime datetime, unload_density float, loadserialnumber int);/*load initial data to work with*/INSERT INTO ##data VALUES('2010-10-09 13:26:36.000',1.01059,252);INSERT INTO ##data VALUES('2010-10-09 13:26:41.000',1.01068,252);INSERT INTO ##data VALUES('2010-10-09 13:26:46.000',1.02589,252);INSERT INTO ##data VALUES('2010-10-10 08:15:02.000',1.03333,266);INSERT INTO ##data VALUES('2010-10-10 08:15:07.000',1.04444,266);INSERT INTO ##data VALUES('2010-10-10 08:15:12.000',1.01561,266);INSERT INTO ##data VALUES('2010-10-10 08:15:17.000',1.03581,266);INSERT INTO ##data VALUES('2010-10-10 08:15:22.000',1.03554,266);INSERT INTO ##data VALUES('2010-10-08 18:47:45.000',1.04983,302);INSERT INTO ##data VALUES('2010-10-08 18:47:50.000',1.09813,302);INSERT INTO ##data VALUES('2010-10-08 18:47:56.000',1.04576,302);INSERT INTO ##data VALUES('2010-10-08 18:48:01.000',1.03485,302);Result : |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-01-22 : 08:18:31
|
Have a look at pivot operator in books onlinehttp://technet.microsoft.com/en-us/library/ms177410(v=sql.105).aspx------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|
|
|