Link to home
Start Free TrialLog in
Avatar of sameer2010
sameer2010Flag for India

asked on

Name the intermediate resultset

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

Avatar of sameer2010
sameer2010
Flag of India image

ASKER

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

Avatar of Geert G
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
I agree. Please read the same as "procedure" instead of "query".
SOLUTION
Avatar of Geert G
Geert G
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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)
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks a lot...spt_values was a learning for me. :-)
What is the reason for B rating?
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.