Advertisement

04.28.2008 at 12:26PM PDT, ID: 23359905
[x]
Attachment Details

Assigning formatted query result to a variable.

Asked by Walawalkar in SQL Query Syntax

Tags: Microsoft, SQL, 2000, SQL

Hello

This could be a simple task for some of you but I am finding it difficult to write a query for following task.

I am building a query using one variable and then I want to assign the result value of this query to the other variable.

Please let me know how I can do this. I want to run the following code in loop using different values to build a query.

Please help.



Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
declare @query as varchar(500)
declare @num as varchar
declare @value as decimal(9,2)
set @num = 5
set @query = 'select sum(LMP) into from (select top ' + @num + ' * from #tempTable_Asc)t'
print @query
 
Now I want to assign the value of this query to variable @value
 
I know directly it is possible to assign value like
 
set @value = (select sum(LMP) from (select top 5 * from #tempTable_Asc)t)
[+][-]04.28.2008 at 12:28PM PDT, ID: 21456881

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.28.2008 at 01:31PM PDT, ID: 21457358

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.29.2008 at 07:22AM PDT, ID: 21462517

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.29.2008 at 07:41AM PDT, ID: 21462723

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.01.2008 at 01:38PM PDT, ID: 21482524

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.01.2008 at 01:41PM PDT, ID: 21482554

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: SQL Query Syntax
Tags: Microsoft, SQL, 2000, SQL
Sign Up Now!
Solution Provided By: angelIII
Participating Experts: 3
Solution Grade: B
 
 
[+][-]05.01.2008 at 02:05PM PDT, ID: 21482748

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628