Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Name the intermediate resultset

Posted on 2010-01-12
9
Medium Priority
?
283 Views
Last Modified: 2012-05-08
Hi,

Below is a simple query that I am using. I wanted to know -
1. Is it possible to do the same without declaring a variable @a. e.g. some pre-defined dummy system variable.
2. Can the output of this query be captured as a table and used for further processing. PS: I do not want to define temp table.

Thanks,
Sam
declare @a int;
set @a = 0;
while @a < 5
begin
	select @a
	set @a = @a + 1
end;

Open in new window

0
Comment
Question by:sameer2010
  • 5
  • 2
  • 2
9 Comments
 
LVL 13

Author Comment

by:sameer2010
ID: 26293698
By 2nd question, I mean something like the following, which does not work.
declare @a int;
set @a = 0;
SELECT * FROM (
while @a < 5
begin
	select @a
	set @a = @a + 1
end ) T;

Open in new window

0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 26293765
this is not a query
it is a procedure

a procedure is not the same as a query

a procedure can produce output and so can a query
but they are not the same
0
 
LVL 13

Author Comment

by:sameer2010
ID: 26293882
I agree. Please read the same as "procedure" instead of "query".
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 38

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 300 total points
ID: 26293898
to put it simple:
1: no
2: no
0
 
LVL 13

Author Comment

by:sameer2010
ID: 26294007
Okay. I thought the second one should be possible. Because dbms would be storing the data to some storage and it should be possible to aggregate the results from the temp storage (not created by us explicitly though)
0
 
LVL 41

Accepted Solution

by:
Sharath earned 450 total points
ID: 26294107
It depends on what you are looking for. If you want to display the numbers from 1 to 5, you can simply try with spt_values table.

SELECT number FROM master..spt_values WHERE type = 'P' AND number BETWEEN 1 AND 5
0
 
LVL 13

Author Closing Comment

by:sameer2010
ID: 31676119
Thanks a lot...spt_values was a learning for me. :-)
0
 
LVL 41

Expert Comment

by:Sharath
ID: 26315092
What is the reason for B rating?
0
 
LVL 13

Author Comment

by:sameer2010
ID: 26315149
I had two related questions.
1. Do we have some pre-defined variable which can be used? The answer is No
2. Is it possible to store the resultset in some table without declaration and insert? The anwer is No.

While spt_values was a learning, and an interesting way to generate the series, my original question was different.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question