Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 How do I add a row to the top of a recordset ?

Author  Topic 

tuka
Starting Member

26 Posts

Posted - 2006-12-23 : 11:29:20

Hi,

I am trying to add a single row at the top of a rescorset like

select id, name from tb_industry

how do I add at the top of that recordset a row 0, "-Select One-" so that the result looks like this ?


id name
0 -Select One-
1 Agriculture
2 Automobile


I have considered UNION but it requires a table to select from in the first plce acoording to few exmples I have seen. What I want to add is just a sible row to add options to a list box on an app. I would like the option to be included at the sql server layer.

TIA,
Tuka

PS: Of course I can always generate a temporary table and do a UNION both that is a verbose way of doing it. I would like something a little more eleganet

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2006-12-23 : 11:37:12
A union is the right way to go

SELECT 0 AS ID, '-Select One-' AS Name
UNION
SELECT ID, Name FROM tb_industry
ORDER BY ID
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2006-12-23 : 15:00:39
I would use UNION ALL in this case instead of UNION,

UNION is more expensive than UNION ALL because it needs to check for dupes.


www.elsasoft.org
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-12-24 : 23:34:53
<<
UNION is more expensive than UNION ALL because it needs to check for dupes.
>>
Also it will sort the records

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

tuka
Starting Member

26 Posts

Posted - 2006-12-25 : 09:20:08
Thanks a lot guys for the input. It was all very helpful.

Cheers,
Tuka
Go to Top of Page
   

- Advertisement -