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)
 Append a value from a select

Author  Topic 

sg2255551
Constraint Violating Yak Guru

274 Posts

Posted - 2009-02-09 : 10:34:01
hi

I have a table(Type) with values A,B,C,D

I want to add a "All" value from a select

For example
Select Type from Table
union all
Select 'A'

This would result in

All
A
B
C
D

How should i go about it? Thanks

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-02-09 : 10:37:00
Select 'All'
union all
Select Type from Table


Madhivanan

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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-09 : 10:43:35
[code]SELECT Val
FROM
(
Select Type AS Val,1 AS Ord from Table
union all
Select 'All',0
)t
ORDER BY Ord
[/code]
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-02-09 : 10:46:08
quote:
Originally posted by visakh16

SELECT Val
FROM
(
Select Type AS Val,1 AS Ord from Table
union all
Select 'All',0
)t
ORDER BY Ord



You dont need it when you use UNION ALL

Madhivanan

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

sg2255551
Constraint Violating Yak Guru

274 Posts

Posted - 2009-02-09 : 12:24:20
Thank you so much.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-09 : 12:32:39
welcome
Go to Top of Page
   

- Advertisement -