473,725 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing parameters to nested parameter queries

WGW
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.sha dow
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.typ eid
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='x xxx']? (Maybe I should try that! I've
seen nothing about it though.)

My parameter query, [e_typerows], looks like this in fact:

@typestringpara meter varchar(100) = "yyyy"

SELECT dbo.bi_dictiona ry_e.typestring , dbo.bi_occ_01_e .row
FROM dbo.bi_occ_01_e INNER JOIN
dbo.bi_dictiona ry_e ON
dbo.bi_occ_01_e .typeid = dbo.bi_dictiona ry_e.typeid
GROUP BY dbo.bi_dictiona ry_e.typestring ,
dbo.bi_occ_01_e .row
HAVING (dbo.bi_diction ary_e.typestrin g = @typestringpara meter)

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.)

Jul 20 '05 #1
3 16944
WGW <wi****@interch ange.ubc.ca> wrote in message news:<bu******* ***@nntp.itserv ices.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.sha dow
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.typ eid
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='x xxx']? (Maybe I should try that! I've
seen nothing about it though.)

My parameter query, [e_typerows], looks like this in fact:

@typestringpara meter varchar(100) = "yyyy"

SELECT dbo.bi_dictiona ry_e.typestring , dbo.bi_occ_01_e .row
FROM dbo.bi_occ_01_e INNER JOIN
dbo.bi_dictiona ry_e ON
dbo.bi_occ_01_e .typeid = dbo.bi_dictiona ry_e.typeid
GROUP BY dbo.bi_dictiona ry_e.typestring ,
dbo.bi_occ_01_e .row
HAVING (dbo.bi_diction ary_e.typestrin g = @typestringpara meter)

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
Jul 20 '05 #2
WGW
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=@pa rameter2 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.a se.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.db o.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****@interch ange.ubc.ca> wrote in message news:<bu******* ***@nntp.itserv ices.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.sha dow
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.typ eid
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='x xxx']? (Maybe I should try that! I've
seen nothing about it though.)

My parameter query, [e_typerows], looks like this in fact:

@typestringpa rameter varchar(100) = "yyyy"

SELECT dbo.bi_dictiona ry_e.typestring , dbo.bi_occ_01_e .row
FROM dbo.bi_occ_01_e INNER JOIN
dbo.bi_dictio nary_e ON
dbo.bi_occ_01 _e.typeid = dbo.bi_dictiona ry_e.typeid
GROUP BY dbo.bi_dictiona ry_e.typestring ,
dbo.bi_occ_01 _e.row
HAVING (dbo.bi_diction ary_e.typestrin g = @typestringpara meter)

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


Jul 20 '05 #3
WGW (wi****@interch ange.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
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
17354
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 (update, append) should be activated in order to transfer data to other tables. I tried to avoid any coding in VB, as I am not a professional, but I have found a statement in an article, that, unlike select queries, form's Input Property can't be...
1
2484
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
1
5727
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: Dim db as DAO.Database, qd as DAO.QueryDef, prm as DAO.Parameter Set db = Currentdb Set qd = db.QueryDefs("aaTest") For Each prm In qd.Parameters prm.Value = Eval(prm.Name)
1
3635
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 make a report( VS.NET, C#, Web Form) with 3 parts and with data from three tables: 1st part: all the field values form table1 coresponding to an Id (Id
4
3001
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 pass it to the Db and retrieveing data from a stored procedure, but I can't get the hang of parameters. I have a method where I can get the parameters passed to the sp but it doesn't want to return any results. Here's a copy of my code:
2
2024
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 as was the case in the previous version of VB e.g. VB .Net 2003. Here's the procedure in the web service: Public Sub Convert2Dollar(ByVal euroAmount As Double, ByRef usDollarAmount As Double) Dim exchangeRate As Double exchangeRate = 10 / 6
10
3930
by: amazon | last post by:
Our vender provided us a web service: 1xyztest.xsd file... ------------------------------------ postEvent PostEventRequest ------------------------------------- authetication authentication eventname string source string ID string
9
1538
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 was a poll on this features continued existence taken at PyCon and it could go.
11
3693
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 IIf(IsNull(!!),"%",<!!) The idea is that if there's value in the field then the parameter is carried into the query. If the box is empty then it's not. Using: <!! as a parameter on its own works fine but then I lose the vital iif() function. But using the...
0
8752
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9401
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9257
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8096
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6702
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6011
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4517
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2634
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.