user6858405
user6858405

Reputation:

Add row to stored procedure in SQL Server

What's the syntax to add a pre-defined row to the return values of a stored procedure?

Let's say I select some rows from a View and, additionally, want the procedure to return another pre-defined row.

Is this only possible by filling up a table?

Upvotes: 1

Views: 263

Answers (2)

GuidoG
GuidoG

Reputation: 12014

you can do this with union all, and if you want the predefined row to be the last row you can add an order by like this

select 0 as sortvalue, 
       table1.*
from   table1
union all
select 1 as sortvalue,
       predefined values...
order by 1

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1269893

I think you are looking for UNION ALL.

You can run a query like this:

select . ..
from . . .
union all
select . . .;

Note that without an ORDER BY, result sets are unordered. So the additional row might not be the "last" in the result set.

Upvotes: 2

Related Questions