I have a dropdown list which gets its data from a one column returning select query.
I would like to add a static value to this list which does not come from the database.
How can I append my dataset with this one value?
I am trying to avoid using a gateway script…
Add the static value to your query by using a UNION
SELECT myColumn FROM myTable
UNION
SELECT "myStaticValue" as myColumn
Thanks Pat
How could I then order my dataset so the static value is the first one?
I’ve tried
ORDER BY (mycolumn = 'Static') DESC
and a few others
ORDER BY CASE WHEN mycolumn = 'Static' THEN 1 ELSE 2 END
None work for me.
Change the order of your select statements
SELECT "myStaticValue" as myColumn
UNION
SELECT myColumn FROM myTable
This doesn’t seem to effect the order for me, Using MS SQL Server 2008.
Something like this:
(SELECT myColumn, 1 as myOrder
FROM myTable)
UNION
(SELECT "myStaticValue" as myColumn, 2 as myOrder)
ORDER BY myOrder ASC