0

I have a set of results from a WSUS report that consists of computername and the status level of patching on that computer.

I have been asked to display this as a heatmap e.g each computer is a single cell with a color assigned depending on the patch status (e.g. failed, waiting for reboot, downloaded etc) and to do this I need some columns to use as axis. Heatmaps needs 3 columns (x,y and heat) I only have the heat at the moment.

I can do this with cursors iterating over each row incrementing the counters for two columns and inserting the row plus these two values into a temp table and then return that but it is not efficient.

Is there a better way of doing this?

Ultimately I am after

Computer Name | Heat | X | Y
Comp1         | 4    | 1 | 1
Comp2         | 4    | 1 | 2
Comp3         | 4    | 2 | 1
Comp4         | 4    | 2 | 2

Where X & Y are the generated columns (i.e. not in the data returned from the query)

I am using SQL Server Express 2014 for dev but the production target will probably be 2012 or 2014 full version.

0

1 Answer 1

0

Answer originally left by the question author in a comment

Final solution was:

SELECT 
    ..., 
    (((ROW_NUMBER() OVER (ORDER BY (SELECT 1))) -1 ) / @cnt) + 1 AS X,
    (((ROW_NUMBER() OVER (ORDER BY (SELECT 1))) -1 ) % @cnt) + 1 AS X

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.