Pivots, man...I'm just missing it. Maybe it's because I'm not doing an aggregate. Heck, maybe a pivot isn't the way to do this. It feels like it should be simple, but it's got me stumped.
Let's say I've got this:
SELECT col1
FROM tbl1
col1
====
414
589
How can I get these two records back as:
fauxfield1 fauxfield2
========== ==========
414 589
Couple of caveats for the purposes of this question
- I'm never going to get back more than two records
- I'm always going to get back integers, but I don't know what they will be.
If you're only ever going to have 2 values, you could do it like this
What I don't understand however is why there is a need to avoid aggregates? Have you found some crippled version of SQL Server? The normal query would be
You can implement the
PIVOT
operator:See SQL Fiddle with Demo
If you know you're only getting two, why not this:
This only shows a second value if there are two.