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 2005 Forums
 Transact-SQL (2005)
 add a new row on fly, when doing a "SELECT * FROM"

Author  Topic 

rum23
Yak Posting Veteran

77 Posts

Posted - 2008-10-19 : 16:56:19

I want to add a row on fly when doing a "select * from table1".If table1 has 2 columns, I want add a row called "ALL" before returning the recordset to the user. Is this possible to do in SQL? The data should look something like this

Table1:

Column1 Column2
All All
John Smith
Dug Johnson
Patrick Howard

and so forth.

The "All" row should be added via the SQL select statement. Is this possible atall?

Thanks for your help.

rum23

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-10-19 : 17:03:19
SELECT 'All' AS Column1, 'All' AS Column2
UNION ALL
SELECT Column1, Column2
FROM Table1

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

rum23
Yak Posting Veteran

77 Posts

Posted - 2008-10-19 : 17:16:59

Great, Thanks!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-10-20 : 04:00:28
Do you want to show data in a Dropdown control?
If so, you can easily append the text you want there before populating the data
You may need to convert data to varchar if it is of different datatype when you do this in sql


Madhivanan

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

- Advertisement -