[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.3

Please help with this dynamic TSQL insert SP results + 1 of the parameter passed

Asked by sqlagent007 in MS SQL Server, SQL Query Syntax

Tags: sql server

I am executing a stored proc for every record in a table, I have to walk the data so to speak.

I execute the stored proc for each MTUID in a table, passing the MTUID to the stroed proc as an input parameter, and then insert the results into a table, this all works fine.

The results of the stored proc return the metadata about the MTUID that I passed into the stored proc, however I also need that ID inserted into the table with the metadata.

Example: EXEC SP_GetData 6543456

This would return everything about MTU 6543456, I take the output of this and put it in a table. Now I need to keep that output with the MTUID of 6543456 and insert all that as 1 row into my table.

I have posted my code below; please help me fix this so that the @MTUID is also inserted with the metadata.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
IF OBJECT_ID('tempdb..#dailyCon') IS NOT NULL DROP TABLE #dailyCon
-------------------------------------------
-- create table to store values --
-------------------------------------------
create table #dailyCon
(rownum int IDENTITY (1, 1),
readingDate datetime,
RawCons int,
Cons decimal(20,6),
Scalar int,
units int,
Utility varchar (20),
accNum varchar (15),
SerialNumber int,
MTUID int)
-------------------------------------------
-- create table to store values --
-------------------------------------------
-- VARIABLE DECLARATION  
declare @Proc nvarchar(200)
declare @RowCnt int
declare @MaxRows int
declare @ExecSql nvarchar(255)
declare @Day1b datetime
declare @Day1e datetime 
declare @strDay1b nvarchar(50)
declare @strDay1e nvarchar(50)
-- VARIABLE DECLARATION 
-- SETTING THE VARIABLES 
select @RowCnt = 1
select @Proc = 'MyDB.dbo.USP_GetStuff'
select @Day1b = DATEDIFF(dd, 1, GETDATE()) 
select @Day1e = DATEadd(mi, 1439, @Day1b) 
set @strDay1b  = 'Oct 13 2009 12:00AM'
set @strDay1e  = 'Oct 13 2009 11:59PM' 
-- These next two rows are specific to source table or query
declare @Import1 table (rownum int IDENTITY (1, 1) Primary key NOT NULL , MTUID nvarchar(20),AccountNum nvarchar(20))
insert into @Import1 (MTUID,AccountNum) select [mtuid],AccountNum from dbo.TEST_MTUID order by MTUID 
select @MaxRows=count(*) from @Import1 
while @RowCnt <= @MaxRows
begin
    select @ExecSql = 'insert into #dailyCon (readingDate,RawCons,Cons,Scalar,units,Utility,accNum,SerialNumber)  ' + 'exec ' + @Proc + ' ' + MTUID + '' + ',1,' + '''' +@strDay1b+ '''' + ',' + '''' +@strDay1e+ '''' + ',1,2'  from @Import1 where rownum = @RowCnt 
    --print @ExecSql
    execute sp_executesql @ExecSql
    Select @RowCnt = @RowCnt + 1
end 
IF OBJECT_ID('tempdb..#dailyCon') IS NOT NULL DROP TABLE #dailyCon
[+][-]11/06/09 03:01 PM, ID: 25763835Accepted Solution

View this solution now by starting your 30-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

Zones: MS SQL Server, SQL Query Syntax
Tags: sql server
Sign Up Now!
Solution Provided By: aneeshattingal
Participating Experts: 1
Solution Grade: A
 
 
Loading Advertisement...
20091111-EE-VQP-92 - Hierarchy / EE_QW_3_20080625