Kimball Robinson
Kimball Robinson

Reputation: 3387

Include a blank row in query results

Is there a way to include a blank row at the top of a sql query, eg if it is meant for a dropdown list? (MS Sql Server 2005 or 2008)

Select * 
  FROM datStatus 
ORDER BY statusName

Where I want something like

  -1  (please choose one)
  1   Beginning
  2   Middle
  3   Ending
  4   Canceled

From a table that is ordinarily just the above, but without the top row?

Upvotes: 1

Views: 15407

Answers (3)

Amadan
Amadan

Reputation: 198324

I feel it's nicer to do it outside SQL, but if you insist...

SELECT -1, '(please choose one)'
UNION
SELECT * FROM datStatus
ORDER BY statusName

Upvotes: 8

Jubal
Jubal

Reputation: 8717

How about unioning the first row together with the rest of the query?

Select -1,'(please choose one)'
union all
select * FROM datStatus ORDER BY statusName

Upvotes: 2

Doug
Doug

Reputation: 5318

I have found that it is better to do this in the presentation layer of your application, as you might have different requirements based on the context. In general I try to keep my data service layer free of these sorts of implementation specific rules. So in your case I would usually just add a new item by index in the first position of the list, after i had loaded it with data from my service layer.

Enjoy!

Upvotes: 4

Related Questions