Hi all
I have about 5 stored procedures that, among other things, execute exactly the same SELECT statement
Instead of copying the SELECT statement 5 times, I'd like each stored proc to call a single stored proc that executes the SELECT statement and returns the resultset to the calling stored proc
The SELECT statement in question retrieves a single row from a table containing 10 columns.
Is there a way for a stored proc to call another stored proc and gain access to the resultset of the called stored proc?
I know about stored proc return values and about output parameters, but I think I am looking for something different.
ThanksYou can create a table variable and return it to the outer proc ... i assume thats what you are looking for
:)|||instead of procedure create a table-value udf|||If SQLServer 2000, use the @.table datatype
If SQLServer 7.0, create a temp table in proc 1 and populate it in proc 2 (just be aware of that proc 2 is gonna recompile each time its run)|||If it's Always just 1 row (are you sure) wht not pass back OUTPUT variables?|||Originally posted by Jonte
If SQLServer 2000, use the @.table datatype
If SQLServer 7.0, create a temp table in proc 1 and populate it in proc 2 (just be aware of that proc 2 is gonna recompile each time its run)
Thanks to Enigma, ms_sql_dba and Jonte. A table variable is exactly what I was searching for.|||Originally posted by Brett Kaiser
If it's Always just 1 row (are you sure) wht not pass back OUTPUT variables?
Hi
I was looking for a solution where I didnt have to declare 10+ output variables, or one that would work on occassions where there is more than 1 row returned
However, I understand that output variables are generally better for performance that using a table variable?|||Originally posted by mattkrevs
Hi
I was looking for a solution where I didnt have to declare 10+ output variables, or one that would work on occassions where there is more than 1 row returned
However, I understand that output variables are generally better for performance that using a table variable?
Well, obviously, if you had a table variable with 15 columns or you had 15 output parameters, then the 15 output parameters would have less overhead.
Oh, and don't use UDF's when you can use SP's. UDF don't get precompiled.|||Originally posted by mattkrevs
Hi
I was looking for a solution where I didnt have to declare 10+ output variables, or one that would work on occassions where there is more than 1 row returned
However, I understand that output variables are generally better for performance that using a table variable?
I like lazy...
But it seems misguided...you still have to code the local table variables anyway...
And in what instances will you get more than 1 row...
what would you do wiuth them...sounds like you need to make a decision anyway...why not do it in the sproc?|||Originally posted by beyond cool
Oh, and don't use UDF's when you can use SP's. UDF don't get precompiled.
Can you explain in more detail what you mean by that?|||Originally posted by Brett Kaiser
I like lazy...
But it seems misguided...you still have to code the local table variables anyway...
And in what instances will you get more than 1 row...
what would you do wiuth them...sounds like you need to make a decision anyway...why not do it in the sproc?
Hmmm. You know me too well. Yes its a bit lazy I guess. The stored proc I want to create and call checks for the existance of a row in a table and creates it if it doesnt find it.
Since the calling stored procs only needs info on 2 of the columns of the created row at present then I guess output params might be the best option.
I am interested in the table variable as it is a little more flexible and future proof as I can make all of the columns in the created row available to all calling stored procs.|||Originally posted by mattkrevs
Hmmm. You know me too well. Yes its a bit lazy I guess. The stored proc I want to create and call checks for the existance of a row in a table and creates it if it doesnt find it.
Since the calling stored procs only needs info on 2 of the columns of the created row at present then I guess output params might be the best option.
I am interested in the table variable as it is a little more flexible and future proof as I can make all of the columns in the created row available to all calling stored procs.
Brett - I think I'll go with your output parameters option. I found 2 problems with using table variables
1. I didnt realise you had to fully declare table variables including the table structure. Kind of defeats the purpose of 'lazy' coding
2. I tried this and I got the error "EXECUTE cannot be used as a source when inserting into a table variable." so it looks like it doesnt work anyway. I found other posters had the same problem and they ended up using temp tables instead.|||Hey, don't get me wrong...lazy is a good thing...
It means you're trying to find more effecient ways to do something, rather than the long way around...
Can you posted what you tried though? I'm curious as to why it didn't work for you...|||I kinda like the concept of lazy (http://www.lazydba.com/lazydba_info.html) coding.
Its fun and its challenging!!!!
I believe the laziest i've encountered has to be this one (http://www.dbforums.com/showthread.php?threadid=975995)|||Good site, Enigma
Showing posts with label among. Show all posts
Showing posts with label among. Show all posts
Tuesday, March 27, 2012
Friday, February 24, 2012
Calculations among Subreports
I have three subreports in detail section of main report.The first two subreports have detail records.In third subreport i want to diplay result of sum of values on two of the subreports record wise as below :
SUBREPORT 1 SUBREPORT2 SUBREPORT3
55 65 120
100 35
61 45
Problem is only result for first record on subreports is being displayed whereas i want for all.I am doing all this by using shared variables on subreports.I 've also used whileprintingrecords statement before defining shared variables.Is there any way to solve this problem.Can you explain a bit in detail?
SUBREPORT 1 SUBREPORT2 SUBREPORT3
55 65 120
100 35
61 45
Problem is only result for first record on subreports is being displayed whereas i want for all.I am doing all this by using shared variables on subreports.I 've also used whileprintingrecords statement before defining shared variables.Is there any way to solve this problem.Can you explain a bit in detail?
Calculations among Subreports
I have three subreports on my main reports.what I need is that on third subreport i have a formula thats subtracting two values from two subreports beside it.Values are defined in shared variable on subreports.Formula on third subreport is accessing those shared
variables and doing calculation.Problem is:
Formula is displaying result only for the first record on subreports ,whereas i want the result of calculation for all the corresponding records.
(First 2 subreports are linked with main report)check in formula functions have you added
WhilePrintingRecords to the start of your formulas.|||I have whileprintingrecods statment in mu formula.formula is :
whileprintingrecords;
shared numbervar firstnumber;
shared numbervar secondnumber;
firstnumber - secondnumber|||Are the variables also defined in the main report?
Do you have WhilePrintingRecords in all formulas using these variables?
And what do you mean by 'from two subreports beside it'. Where are the subreports in the design?|||Here's what i am doing:
1) three subreports on main report.
2) third subreport is using shared variables from two subreport
3) before describing the shared variables in 1st two subreports i am using
whileprintingrecords;
shared numbervar firstnumber := command.hours
(same in 2nd subreport)
4) Formula in 3rd subreport:
whileprintingrecords;
shared numbervar firstnumber;
shared numbervar secondnumber;
secondnumber - firstnumber
5) When report is printing ,its displaying result only for first record.|||Where are the subreports in the main report's design?
What do you mean by "its displaying result only for first record"? The first record in the main report? The first record per subreport? How many records can the subreports have? Can the first two subreports have no records, meaning the variables won't be (re)set.
So many questions...|||Formula is displaying result only for the first record on subreports ,whereas i want the result of calculation for all the corresponding records.
firstly create a formula on main report
called for sample :
init_var
shared numbervar firstnumber:=0;
shared numbervar secondnumber:=0;
it formula put in header of main report.
now on sub report, create formulla
called for sample :
/************************************************/
calculate_values_SR1
shared numbervar firstnumber;
firstnumber:=myfield_value + firstnumber;
it formula put in detail of first sub report.(I assume your data are there.)
in each detail the formula does work again
/************************************************/
calculate_values_SR2
shared numbervar secondnumber;
secondnumber:=myfield_value + secondnumber;
it formula put in detail of second sub report.
/************************************************/
now on yur third sub report
shared numbervar firstnumber;
shared numbervar secondnumber;
secondnumber - firstnumber
I hope it gives a idea.|||Reply to JaganEllis questions:
1) The first record per subreport?
Yes, i need to print resluts of all records on 1st 2 subreport on 3rd subreport correspondingly.
5 10 15
9 11 20
2) How many records can the subreports have?
depends on records in table
3) Can the first two subreports have no records, meaning the variables won't be (re)set.
it is possible.
Subreports are in detail section of Main report.
Reply to Hensa22
--------
Your solution is not working on dummy data (my own test report) but seemed to work on actual report but as table has not enough values so not able to tell how reliable it is.
variables and doing calculation.Problem is:
Formula is displaying result only for the first record on subreports ,whereas i want the result of calculation for all the corresponding records.
(First 2 subreports are linked with main report)check in formula functions have you added
WhilePrintingRecords to the start of your formulas.|||I have whileprintingrecods statment in mu formula.formula is :
whileprintingrecords;
shared numbervar firstnumber;
shared numbervar secondnumber;
firstnumber - secondnumber|||Are the variables also defined in the main report?
Do you have WhilePrintingRecords in all formulas using these variables?
And what do you mean by 'from two subreports beside it'. Where are the subreports in the design?|||Here's what i am doing:
1) three subreports on main report.
2) third subreport is using shared variables from two subreport
3) before describing the shared variables in 1st two subreports i am using
whileprintingrecords;
shared numbervar firstnumber := command.hours
(same in 2nd subreport)
4) Formula in 3rd subreport:
whileprintingrecords;
shared numbervar firstnumber;
shared numbervar secondnumber;
secondnumber - firstnumber
5) When report is printing ,its displaying result only for first record.|||Where are the subreports in the main report's design?
What do you mean by "its displaying result only for first record"? The first record in the main report? The first record per subreport? How many records can the subreports have? Can the first two subreports have no records, meaning the variables won't be (re)set.
So many questions...|||Formula is displaying result only for the first record on subreports ,whereas i want the result of calculation for all the corresponding records.
firstly create a formula on main report
called for sample :
init_var
shared numbervar firstnumber:=0;
shared numbervar secondnumber:=0;
it formula put in header of main report.
now on sub report, create formulla
called for sample :
/************************************************/
calculate_values_SR1
shared numbervar firstnumber;
firstnumber:=myfield_value + firstnumber;
it formula put in detail of first sub report.(I assume your data are there.)
in each detail the formula does work again
/************************************************/
calculate_values_SR2
shared numbervar secondnumber;
secondnumber:=myfield_value + secondnumber;
it formula put in detail of second sub report.
/************************************************/
now on yur third sub report
shared numbervar firstnumber;
shared numbervar secondnumber;
secondnumber - firstnumber
I hope it gives a idea.|||Reply to JaganEllis questions:
1) The first record per subreport?
Yes, i need to print resluts of all records on 1st 2 subreport on 3rd subreport correspondingly.
5 10 15
9 11 20
2) How many records can the subreports have?
depends on records in table
3) Can the first two subreports have no records, meaning the variables won't be (re)set.
it is possible.
Subreports are in detail section of Main report.
Reply to Hensa22
--------
Your solution is not working on dummy data (my own test report) but seemed to work on actual report but as table has not enough values so not able to tell how reliable it is.
Calculations among Subreports
Question again regarding calculation on subreports.I have attached a part of my report,so its more clear what i am looking for i.e Subreport 3 is displaying result based on values from subreports 1 and 2 but only result for the first record on subreports is being displayed.Question again regarding calculation on subreports.I have attached a part of my report,so its more clear what i am looking for i.e Subreport 3 is displaying result based on values from subreports 1 and 2 but only result for the first record on subreports is being displayed.
Where is the attachment?|||I myself have no idea where's the attachement gone,but anyways here 's a snapshopt of whats happening:
SUBREPORT 1 SUBREPORT2 SUBREPORT3
5 10 15
9 6
11 3
10 5
i guess its clear now!|||its not displaying the data as required ,the number below the subreport headings are three columns each under corresponding subreports.
Where is the attachment?|||I myself have no idea where's the attachement gone,but anyways here 's a snapshopt of whats happening:
SUBREPORT 1 SUBREPORT2 SUBREPORT3
5 10 15
9 6
11 3
10 5
i guess its clear now!|||its not displaying the data as required ,the number below the subreport headings are three columns each under corresponding subreports.
Labels:
among,
attached,
calculation,
calculations,
clear,
database,
microsoft,
mysql,
oracle,
regarding,
report,
server,
sql,
subreport,
subreports
Subscribe to:
Posts (Atom)