question

nileshamruskarsqlserver avatar image
nileshamruskarsqlserver asked

!!!T-SQL Query Help

Can some help with the Tsql query to bring data as per below aligned format without null values. Need it urgent. ![alt text][1] ![alt text][2] [1]: /storage/temp/3712-2016-10-07-1249.png [2]: /storage/temp/3713-untitled.png
t-sqlstored-procedurestsqlstored procedures
2016-10-07-1249.png (17.2 KiB)
untitled.png (6.9 KiB)
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

sjimmo avatar image sjimmo commented ·
What have you tried? What is the schema for the table(s)
0 Likes 0 ·
nileshamruskarsqlserver avatar image nileshamruskarsqlserver commented ·
I have tried everything right from joins to pivot. tried cte too. now I am doing it by while loop but its not accurate.. I think its not possible to bring such data in the given format. And also data is not constant in each column so in this case I dont think it can be done.
0 Likes 0 ·

1 Answer

·
Magnus Ahlkvist avatar image
Magnus Ahlkvist answered
If there's no key between what makes 970469 come together with 963005, there's no way to solve this. Data in a table is unordered by definition (regardless of clustering key and therefore physical sort order on disk). In order to solve this, you need a key to order the data on. Even if a Query gives you the result that 970469 comes Before 1027486, it might just as well end up the other way around the next time you run a select Query. Perhaps you have a primary key in this table, which is not shown in your example, but if you don't, you have a problem which cannot be solved.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.