Though I am a novice to MS SQL server (2000 I believe), I can do almost!
everything I need. Maybe not efficiently, but usefully. However, I have
a problem -- a complex query problem...
I can create a parameter query in a stored procedure, but how do I use
the result set of a parameter query in a select query (in the same or
another sp)? In short, if a select query contains a result table that is
generated as a parameter query, how do I pass the parameter through the
select query to the nested parameter query?
For example, if I have a sp parameter query called [e_typerows], I could
write the following select query which uses the (single) result set from
[e_typerows] plus other tables or views:
SELECT TOP 100 PERCENT bi_occ_01_e.row, bi_occ_01_e.pos,
bi_dictionary_e.typestring, bi_occ_01_e.shadow
FROM bi_dictionary_e INNER JOIN
(bi_occ_01_e INNER JOIN
[e_typerows] ON bi_occ_01_e.row = [e_typerows].row) ON
bi_dictionary_e.typeid = bi_occ_01_e.typeid
ORDER BY bi_occ_01_e.row, bi_occ_01_e.pos
Even though [e_typerows] is a (storted procedure) parameter query this
will work IF my parameter in [e_typerows] has a default, say "yyyy". In
the default case no parameter needs passing. But what if it doesn't have
a default value or if I need to pass a parameter to it?
Is there any way to replace[e_typerows]in the above query with something
like [e_typerows @myparameter='xxxx']? (Maybe I should try that! I've
seen nothing about it though.)
My parameter query, [e_typerows], looks like this in fact:
@typestringparameter varchar(100) = "yyyy"
SELECT dbo.bi_dictionary_e.typestring, dbo.bi_occ_01_e.row
FROM dbo.bi_occ_01_e INNER JOIN
dbo.bi_dictionary_e ON
dbo.bi_occ_01_e.typeid = dbo.bi_dictionary_e.typeid
GROUP BY dbo.bi_dictionary_e.typestring,
dbo.bi_occ_01_e.row
HAVING (dbo.bi_dictionary_e.typestring = @typestringparameter)
Any suggestions would be greatly appreciated! (For the moment, I first
generate the parameter query result set, then I loop through each row of
that result set and do a select query with that row as a parameter --
very complicated!, though it does work.) 3 16853
WGW <wi****@interchange.ubc.ca> wrote in message news:<bu**********@nntp.itservices.ubc.ca>... Though I am a novice to MS SQL server (2000 I believe), I can do almost! everything I need. Maybe not efficiently, but usefully. However, I have a problem -- a complex query problem...
I can create a parameter query in a stored procedure, but how do I use the result set of a parameter query in a select query (in the same or another sp)? In short, if a select query contains a result table that is generated as a parameter query, how do I pass the parameter through the select query to the nested parameter query?
For example, if I have a sp parameter query called [e_typerows], I could write the following select query which uses the (single) result set from [e_typerows] plus other tables or views:
SELECT TOP 100 PERCENT bi_occ_01_e.row, bi_occ_01_e.pos, bi_dictionary_e.typestring, bi_occ_01_e.shadow FROM bi_dictionary_e INNER JOIN (bi_occ_01_e INNER JOIN [e_typerows] ON bi_occ_01_e.row = [e_typerows].row) ON bi_dictionary_e.typeid = bi_occ_01_e.typeid ORDER BY bi_occ_01_e.row, bi_occ_01_e.pos
Even though [e_typerows] is a (storted procedure) parameter query this will work IF my parameter in [e_typerows] has a default, say "yyyy". In the default case no parameter needs passing. But what if it doesn't have a default value or if I need to pass a parameter to it?
Is there any way to replace[e_typerows]in the above query with something like [e_typerows @myparameter='xxxx']? (Maybe I should try that! I've seen nothing about it though.)
My parameter query, [e_typerows], looks like this in fact:
@typestringparameter varchar(100) = "yyyy"
SELECT dbo.bi_dictionary_e.typestring, dbo.bi_occ_01_e.row FROM dbo.bi_occ_01_e INNER JOIN dbo.bi_dictionary_e ON dbo.bi_occ_01_e.typeid = dbo.bi_dictionary_e.typeid GROUP BY dbo.bi_dictionary_e.typestring, dbo.bi_occ_01_e.row HAVING (dbo.bi_dictionary_e.typestring = @typestringparameter)
Any suggestions would be greatly appreciated! (For the moment, I first generate the parameter query result set, then I loop through each row of that result set and do a select query with that row as a parameter -- very complicated!, though it does work.)
I'm not sure I follow your logic above, but if you're asking how to
re-use or query the result set from a stored procedure, then you can
find a good discussion of the options here: http://www.sommarskog.se/share_data.html
Simon
Thanks for the pointer: I think it will lead me finally to the answer to
my question, which I have a feeling is too simple to be understood.. in
simple terms!
I think I to do something trivial. It is really simply a call between
two procedures: >>>>>>>>>>
stored procedure 1:
CREATE PROCEDURE parameter_test @parameter1 varchar(100)
AS
select top 10 u_id from test
where u_id= @parameter1
GO
stored procedure 2:
CREATE PROCEDURE select_test @parameter2 varchar(100)
AS
SELECT *
FROM EXEC parameter_test @parameter1=@parameter2 INNER JOIN
test2 ON test.u_id = test2.u_id
GO
<<<<<<<<<<<<<<<<<<<<
I didn't understand that an EXEC returns a result set that is like any
other table. The @parameter2 is not being used as such in the select of
procedure 2, but rather in the procedure 1; the parameter is passed to
the nested sp1. Will that work? I will go experiment!
I think the difficulty here is I am simply too little informed to ask
the question properly.
Thanks for the help!
Bill
I found two other tips. The second seems the most general: "how to feed
the result set of one procedure into another".
The first (http://dbforums.com/t576857.html)is : >>>>>>>>>>
P.S. I have tried to insert the result set into a temp table in MS SQL
Server 97. Can I do the same thing in sybase? I have tried the following
stored procedure, but it worked well in MS SQL Server and gave error
"incorrect near exec..." in sybase.
my stored procedures in MS SQL Server 97.
stored procedure 1:
CREATE PROCEDURE [dbo].[testing1] AS
select top 10 u_id from test
GO
stored procedure 2:
CREATE PROCEDURE [dbo].[testing2] AS
CREATE TABLE #abc (u_id char(18))
INSERT #abc
EXEC testing1
SELECT *
FROM #abc
DROP TABLE #abc
GO
<<<<<<<<<<<<<<<
A second description was at http://www.isug.com/Sybase_FAQ/ASE/section6.3.html (but of course it is
not sysbase I am interested in): >>>>>>>>>>>>>>
6.3.1: How to feed the result set of one stored procedure into another.
I am sure that this is all documented, but it is worth adding here. It
uses CIS, as do a number of useful tricks. CIS is disabled by default
before 12.0 and not available before 11.5. It is courtesy of BobW from
sybase.public.ase.general, full acceditation will be granted if I can
find out who he is. Excellent tip!
So, the scenario is that you have a stored procedure, AP_A, and you wish
to use the result set that it returns in a query.
Create a proxy table for SP_A.
create table proxy_SP_A (
a int,
b int,
c int,
_p1 int null,
_p2 int null
) external procedure
at "SELF.dbname.dbo.SP_A"
Columns a, b, c correspond to the result set of SP_A. Columns _p1, _p2
correspond to the @p1, @p2 parameters of SP_A. "SELF" is an alias put in
sysservers to refer back to the local server.
If you only have one row returned the proxy table can be used with the
following:
declare @a int, @b int, @c int
select @a = a, @b = b, @c = c from proxy_SP_B
where _p1 = 3 and _p2 = 5
More rows can be handled with a cursor.
<<<<<<<<<<<<<<<<<
Simon Hayes wrote: WGW <wi****@interchange.ubc.ca> wrote in message news:<bu**********@nntp.itservices.ubc.ca>...
Though I am a novice to MS SQL server (2000 I believe), I can do almost! everything I need. Maybe not efficiently, but usefully. However, I have a problem -- a complex query problem...
I can create a parameter query in a stored procedure, but how do I use the result set of a parameter query in a select query (in the same or another sp)? In short, if a select query contains a result table that is generated as a parameter query, how do I pass the parameter through the select query to the nested parameter query?
For example, if I have a sp parameter query called [e_typerows], I could write the following select query which uses the (single) result set from [e_typerows] plus other tables or views:
SELECT TOP 100 PERCENT bi_occ_01_e.row, bi_occ_01_e.pos, bi_dictionary_e.typestring, bi_occ_01_e.shadow FROM bi_dictionary_e INNER JOIN (bi_occ_01_e INNER JOIN [e_typerows] ON bi_occ_01_e.row = [e_typerows].row) ON bi_dictionary_e.typeid = bi_occ_01_e.typeid ORDER BY bi_occ_01_e.row, bi_occ_01_e.pos
Even though [e_typerows] is a (storted procedure) parameter query this will work IF my parameter in [e_typerows] has a default, say "yyyy". In the default case no parameter needs passing. But what if it doesn't have a default value or if I need to pass a parameter to it?
Is there any way to replace[e_typerows]in the above query with something like [e_typerows @myparameter='xxxx']? (Maybe I should try that! I've seen nothing about it though.)
My parameter query, [e_typerows], looks like this in fact:
@typestringparameter varchar(100) = "yyyy"
SELECT dbo.bi_dictionary_e.typestring, dbo.bi_occ_01_e.row FROM dbo.bi_occ_01_e INNER JOIN dbo.bi_dictionary_e ON dbo.bi_occ_01_e.typeid = dbo.bi_dictionary_e.typeid GROUP BY dbo.bi_dictionary_e.typestring, dbo.bi_occ_01_e.row HAVING (dbo.bi_dictionary_e.typestring = @typestringparameter)
Any suggestions would be greatly appreciated! (For the moment, I first generate the parameter query result set, then I loop through each row of that result set and do a select query with that row as a parameter -- very complicated!, though it does work.)
I'm not sure I follow your logic above, but if you're asking how to re-use or query the result set from a stored procedure, then you can find a good discussion of the options here:
http://www.sommarskog.se/share_data.html
Simon
WGW (wi****@interchange.ubc.ca) writes: P.S. I have tried to insert the result set into a temp table in MS SQL Server 97. Can I do the same thing in sybase? I have tried the following stored procedure, but it worked well in MS SQL Server and gave error "incorrect near exec..." in sybase.
For a complete answer, you would have to ask in a Sybase forum, but
INSERT EXEC was added to SQL Server 6.5, which was the second version
of SQL Server after the split between Sybase and Microsoft. When 6.0
came it had a couple of new features that also where in System 10,
Sybase first major post-split release, so one could suspect MS got that
with the code base they got from Sybase. But 6.5 news are likely to
be Microsoft's own inventions. (There were new inventions already in
6.0; EXEC() for dynamic SQL for instance.)
--
Erland Sommarskog, SQL Server MVP, so****@algonet.se
Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinf...2000/books.asp This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: zlatko |
last post by:
There is a form in an Access Project (.adp, Access front end with SQL
Server) for entering data into a table for temporary storing. Then, by
clicking a botton, several action stored procedures...
|
by: coffeeboy |
last post by:
When I reference a control on a form in a crosstab criteria field in
complains the expression in invalid. Same criteria works on simple select
query.
Anyone have any ideas?
Thanks
|
by: Bob Darlington |
last post by:
I'm trying to get the following simplified test query to work so that I can
apply it to a more complex final query.
I get a 'Too few parameters' error when I try to run the following append
query:...
|
by: Maria |
last post by:
Hello!
I am new to Crystal reports an I have problems passing parameters form
outside to Crystal report an creating a report with data from more
than one table
This is the problem:
I have to...
|
by: Mike Dinnis |
last post by:
Hi,
I've been working through a number of turorials to try to learn more about
retrieving data from a SQL database. I think i've mastered techniques where
i create a sql string in the page and...
|
by: Nab |
last post by:
I have just tried to pass parameters to a procedure in VB 2005 and realised
that you only need to pass the input parameter. The output parameter's value
will be returned without the need to pass it...
|
by: amazon |
last post by:
Our vender provided us a web service:
1xyztest.xsd file...
------------------------------------
postEvent PostEventRequest
-------------------------------------
authetication authentication...
|
by: Paddy |
last post by:
I blogged on finding a new-to-me feature of Python, in that you are
allowed to nnest parameter definitions:
.... return p0,p1,p2
....
('Does', 'this', 'work')
Ruben commented that there...
|
by: Whizzo |
last post by:
Hi all;
Well, I've had my obligatory hour of Googling, scratching my head and trial and error and now I'm stumped. I'm using the following code as a query parameter:
ALike...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |