?
Solved

Name the intermediate resultset

Posted on 2010-01-12
9
Medium Priority
?
280 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
How To Reduce Deployment Times With Pre-Baked AMIs

Even if we can't include all the files in the base image, we can sometimes include some of the larger files that we would otherwise have to download, and we can also sometimes remove the most time-consuming steps. This can help a lot with reducing deployment times.

 
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

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!

Question has a verified solution.

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

As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month8 days, 23 hours left to enroll

764 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