473,466 Members | 1,455 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Running SP versus SQL Statements

8 New Member
Folks:

I need some help with this. I have a stored procedure which if I run as :

exec test_sptma34 @asofdate = '10/31/2007', @analysisid = 'TVE-2004-10'

would NOT Complete at all and goes in a loop looks like (waited for 12 mins and then cancelled). Whereas If I run the same statements which are in SP then I get around 41 rows and that too within 1 to 2 seconds. Am I missing anything here?


STORED PROCEDURE:
==================
Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE test_spTMA34
  2. (@asofdate DATETIME, 
  3.  @analysisid VARCHAR(50))
  4. AS
  5.  
  6. SET NOCOUNT ON
  7.  
  8. BEGIN
  9.  
  10. declare @ShiftData TABLE
  11. ([BP Shift] float,
  12.  [Elasticity] float,
  13.  [Convexity] float)
  14.  
  15. insert into @ShiftData ([BP Shift], Elasticity, Convexity)
  16. SELECT     cast(substring(D1.datatype, 12, len(D1.datatype)-13) as float) AS '[BP Shift]', 
  17.     SUM(S.Weight*D1.value) AS Elasticity, 
  18.     SUM(S.Weight*D2.Value) AS Convexity
  19. FROM tblData D1
  20. JOIN tblData D2 on D1.asofdate = D2.asofdate and D1.ticker = D2.ticker and Right(D1.datatype,LEN(D1.DataType) - 10) = Right(D2.datatype, LEN(D2.DataType) - 9)
  21. JOIN tblPortfolio P on P.ticker = D1.ticker
  22. JOIN tblSBMIWeights S on S.ticker = D1.ticker
  23. WHERE 
  24. P.portfolio = 'SBMI-TBA' 
  25. and P.asofdate = (SELECT MAX(asofdate) FROM tblPortfolio WHERE portfolio = 'SBMI-TBA' and asofdate <= @asofdate)
  26. and S.asofdate = (SELECT MAX(asofdate) FROM tblSBMIWeights WHERE asofdate <=@asofdate)
  27. and D1.datatype like 'Elasticity@%' AND D1.DataSource = @analysisid
  28. and D2.datatype like 'Convexity@%' AND D2.DataSource = @analysisid
  29. and D1.asofdate = @asofdate
  30. GROUP BY D1.datatype, D2.datatype
  31.  
  32. insert into @ShiftData ([BP Shift], Elasticity, Convexity)
  33. SELECT     0 AS '[BP Shift]', 
  34.     SUM(S.Weight*D1.value) AS Elasticity, 
  35.     SUM(S.Weight*D2.Value) AS Convexity
  36. FROM tblData D1
  37. JOIN tblData D2 on D1.asofdate = D2.asofdate and D1.ticker = D2.ticker and Right(D1.datatype,LEN(D1.DataType) - 10) = Right(D2.datatype, LEN(D2.DataType) - 9)
  38. JOIN tblPortfolio P on P.ticker = D1.ticker
  39. JOIN tblSBMIWeights S on S.ticker = D1.ticker
  40. WHERE 
  41. P.portfolio = 'SBMI-TBA' 
  42. and P.asofdate = (SELECT MAX(asofdate) FROM tblPortfolio WHERE portfolio = 'SBMI-TBA' and asofdate <= @asofdate)
  43. and S.asofdate = (SELECT MAX(asofdate) FROM tblSBMIWeights WHERE asofdate <=@asofdate)
  44. and D1.datatype = 'Elasticity' AND D1.DataSource = @analysisid
  45. and D2.datatype = 'Convexity' AND D2.DataSource = @analysisid
  46. and D1.asofdate = @asofdate
  47. GROUP BY D1.datatype, D2.datatype
  48.  
  49. SELECT * FROM @ShiftData
  50. ORDER BY [BP Shift]
  51.  
  52. END
  53.  

================================================== =======

SAME SQL STATEMENTS (this runs within 1 to 2 secs and returs around 41 rows which is right)
================================================== =====
Expand|Select|Wrap|Line Numbers
  1. SET NOCOUNT ON
  2. BEGIN
  3. declare @asofdate DATETIME, 
  4.         @analysisid VARCHAR(50)
  5.  
  6. SELECT @asofdate = '10/31/2007'
  7. SELECT @analysisid = 'TVE-2004-10'
  8.  
  9. declare @ShiftData TABLE
  10. ([BP Shift] float,
  11.  [Elasticity] float,
  12.  [Convexity] float)
  13.  
  14. insert into @ShiftData ([BP Shift], Elasticity, Convexity)
  15. SELECT     cast(substring(D1.datatype, 12, len(D1.datatype)-13) as float) AS '[BP Shift]', 
  16.     SUM(S.Weight*D1.value) AS Elasticity, 
  17.     SUM(S.Weight*D2.Value) AS Convexity
  18. FROM tblData D1
  19. JOIN tblData D2 on D1.asofdate = D2.asofdate and D1.ticker = D2.ticker and Right(D1.datatype,LEN(D1.DataType) - 10) = Right(D2.datatype, LEN(D2.DataType) - 9)
  20. JOIN tblPortfolio P on P.ticker = D1.ticker
  21. JOIN tblSBMIWeights S on S.ticker = D1.ticker
  22. WHERE 
  23. P.portfolio = 'SBMI-TBA' 
  24. and P.asofdate = (SELECT MAX(asofdate) FROM tblPortfolio WHERE portfolio = 'SBMI-TBA' and asofdate <= @asofdate)
  25. and S.asofdate = (SELECT MAX(asofdate) FROM tblSBMIWeights WHERE asofdate <=@asofdate)
  26. and D1.datatype like 'Elasticity@%' AND D1.DataSource = @analysisid
  27. and D2.datatype like 'Convexity@%' AND D2.DataSource = @analysisid
  28. and D1.asofdate = @asofdate
  29. GROUP BY D1.datatype, D2.datatype
  30.  
  31. insert into @ShiftData ([BP Shift], Elasticity, Convexity)
  32. SELECT     0 AS '[BP Shift]', 
  33.     SUM(S.Weight*D1.value) AS Elasticity, 
  34.     SUM(S.Weight*D2.Value) AS Convexity
  35. FROM tblData D1
  36. JOIN tblData D2 on D1.asofdate = D2.asofdate and D1.ticker = D2.ticker and Right(D1.datatype,LEN(D1.DataType) - 10) = Right(D2.datatype, LEN(D2.DataType) - 9)
  37. JOIN tblPortfolio P on P.ticker = D1.ticker
  38. JOIN tblSBMIWeights S on S.ticker = D1.ticker
  39. WHERE 
  40. P.portfolio = 'SBMI-TBA' 
  41. and P.asofdate = (SELECT MAX(asofdate) FROM tblPortfolio WHERE portfolio = 'SBMI-TBA' and asofdate <= @asofdate)
  42. and S.asofdate = (SELECT MAX(asofdate) FROM tblSBMIWeights WHERE asofdate <=@asofdate)
  43. and D1.datatype = 'Elasticity' AND D1.DataSource = @analysisid
  44. and D2.datatype = 'Convexity' AND D2.DataSource = @analysisid
  45. and D1.asofdate = @asofdate
  46. GROUP BY D1.datatype, D2.datatype
  47.  
  48. SELECT * FROM @ShiftData
  49. ORDER BY [BP Shift]
  50. END
====================
Nov 1 '07 #1
1 1225
debasisdas
8,127 Recognized Expert Expert
Question moved to SQL Server Forum.
Nov 2 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Myster Ious | last post by:
Polymorphism replaces switch statements, making the code more compact/readable/maintainable/OO whatever, fine! What I understand, that needs to be done at the programming level, is this: a...
12
by: Fred | last post by:
Has anyone a link or any information comparing c and c++ as far as execution speed is concerned? Signal Processing algorithms would be welcome... Thanks Fred
2
by: Jason | last post by:
I am trying to get a better understanding of when to use return (with a print statement) and when to use raiserror. * Both statements can be used with stored procedures while only return can be...
1
by: Kevin Frey | last post by:
Hello, I have a test database with table A containing 10,000 rows and a table B containing 100,000 rows. Rows in B are "children" of rows in A - each row in A has 10 related rows in B (ie. B has...
10
by: clueless_google | last post by:
hello. i've been beating my head against a wall over this for too long. setting the variables 'z' or 'y' to differing numbers, the following 'if/else' code snippet works fine; however, the ...
35
by: nagy | last post by:
I do the following. First create lists x,y,z. Then add an element to x using the augumented assignment operator. This causes all the other lists to be changed also. But if I use the assignment...
6
by: radhikutti | last post by:
Hi All, Please explain me the Adv and DisAdv between Procedures and functions Thanks in Advance Radhi
5
patjones
by: patjones | last post by:
Hi: I have a table in my Access database, "tblWC", which contains a field called "fldTrackingStatus". Furthermore, I have a report "rptTrackingReport" which is based on tblWC (using an SQL query...
60
by: harshal | last post by:
Hi all, Can we read the stack frame's of the current process. as we know that whenever a function call is made in c new functions stack frame is created and pushed on to the stack. and when the...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.