dbTalk Databases Forums  

Return results from view with an extra row

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Return results from view with an extra row in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
emanning
 
Posts: n/a

Default Return results from view with an extra row - 01-14-2011 , 09:51 AM






I have a view that returns rows from a table and would like to add an
extra row to the result set, but don't want to add that row in the
table. How do I do this?

My view returns:

Mickey
Minnie
Donald

I'd like the view to return but don't want "NA" added to the table:

Mickey
Minnie
Donald
NA

Thanks.

Reply With Quote
  #2  
Old   
Bob Barrows
 
Posts: n/a

Default Re: Return results from view with an extra row - 01-14-2011 , 09:59 AM






emanning wrote:
Quote:
I have a view that returns rows from a table and would like to add an
extra row to the result set, but don't want to add that row in the
table. How do I do this?

My view returns:

Mickey
Minnie
Donald

I'd like the view to return but don't want "NA" added to the table:

Mickey
Minnie
Donald
NA

It's called a "union" query:

select disneycharactername from disneycharacters
union all
select top 1 'NA' from disneycharacters

This has to be entered in SQL View.

Reply With Quote
  #3  
Old   
Bob Barrows
 
Posts: n/a

Default Re: Return results from view with an extra row - 01-14-2011 , 10:00 AM



Bob Barrows wrote:
Quote:
This has to be entered in SQL View.
Oops, I thought I was in the Access group - of course, this bit is not
relevant to SQL Server.

Reply With Quote
  #4  
Old   
Bob Barrows
 
Posts: n/a

Default Re: Return results from view with an extra row - 01-14-2011 , 10:02 AM



emanning wrote:
Quote:
I have a view that returns rows from a table and would like to add an
extra row to the result set, but don't want to add that row in the
table. How do I do this?

My view returns:

Mickey
Minnie
Donald

I'd like the view to return but don't want "NA" added to the table:

Mickey
Minnie
Donald
NA

aargh, and my suggested query was relevant to JetSQL, not T-SQL. In T-SQL,
one does not need a FROM clause so my suggestion can be simplified to:

select disneycharactername from disneycharacters
union all
select 'NA'

Reply With Quote
  #5  
Old   
emanning
 
Posts: n/a

Default Re: Return results from view with an extra row - 01-14-2011 , 10:15 AM



On Jan 14, 10:02*am, "Bob Barrows" <reb01... (AT) NOyahooSPAM (DOT) com> wrote:
Quote:
emanning wrote:
I have a view that returns rows from a table and would like to add an
extra row to the result set, but don't want to add that row in the
table. *How do I do this?

My view returns:

* * *Mickey
* * *Minnie
* * *Donald

I'd like the view to return but don't want "NA" added to the table:

* * *Mickey
* * *Minnie
* * *Donald
* * *NA

aargh, and my suggested query was relevant to JetSQL, not T-SQL. In T-SQL,
one does not need a FROM clause so my suggestion can be simplified to:

select disneycharactername from disneycharacters
union all
select *'NA'
Got it! Thanks, Bob.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.