Dizzy49
Dizzy49

Reputation: 1520

Possible to Return Set of Values in SQL Server without Return Value?

Here's my situation, I have a table of values that is used to create various reports. I need an ORDER BY in order to group the info the way I need it.

SELECT 
    id, indate, group, lase, first, rank 
FROM 
    this_table
WHERE 
    group = 'SomeGroup'
ORDER BY 
    last, first, indate

I can't use a view because it won't allow the order by. I was hoping I could create a stored procedure to return the result table I want, but without the extra return value.

I've read the comments, and I understand what a view is. I guess the real problem is that I need to get the output into an Excel sheet, and I can only import Views, however I need the data sorted in my output.

Upvotes: 0

Views: 134

Answers (2)

Xedni
Xedni

Reputation: 4695

A view is a passive object that just behaves like a table, but is really the result of a query (un-ordered, as you noticed). The view does do anything by itself. It's when you retrieve the data from the view that you apply your ORDER BY condition(s). The standard way you'd get data out would be by putting your logic in a stored procedure. Alternatively, if you are querying the data ad hoc, you don't even need to use a procedure.

Upvotes: 2

Derviş Kayımbaşıoğlu
Derviş Kayımbaşıoğlu

Reputation: 30585

Create View MyView as
  SELECT id, indate, group, lase, first, rank 
  FROM this_table
    WHERE group = 'SomeGroup';

then

select * from MyView
order by last, first, indate;

Upvotes: 0

Related Questions