473,836 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Stored Query & Parameters.

AJ
Folllowing on from a previous post, i have created a stored query as follows.

SELECT
c.ID, c.Company_Name, p.[level], 1 As QueryNbr
FROM
(Company AS c LEFT JOIN Sale AS s ON c.ID = s.Company_ID)
LEFT JOIN
Package AS p ON s.Package_ID = p.ID
WHERE
c.Category = 'EXH'
AND
(s.ID = (SELECT Max(ID) FROM Sale WHERE Company_ID = c.ID) Or
IsNull(s.ID))
AND
EXISTS(SELECT Company_ID FROM Event_Company_L ink WHERE Event_ID =
@EventID AND Company_ID = c.ID)
AND
(INT(Start_Date ) <= @StartDate) AND (INT(End_Date) >= @EndDate)
ORDER BY
p.[level] DESC , c.Company_Name, c.ID
UNION
SELECT
c.ID, c.Company_Name, p.[level], 2 As QueryNbr
FROM
(Company AS c LEFT JOIN Sale AS s ON c.ID = s.Company_ID)
LEFT JOIN
Package AS p ON s.Package_ID = p.ID
WHERE
c.Category = 'EXH'
AND
(s.ID = (SELECT Max(ID) FROM Sale WHERE Company_ID = c.ID) Or
IsNull(s.ID))
AND
EXISTS(SELECT Company_ID FROM Event_Company_L ink WHERE Event_ID
=@EventID AND Company_ID = c.ID)
ORDER BY
c.Company_Name, c.ID

I want use the results from the preceding query in the following way:

SELECT
ID, Company_Name, level, QueryNbr
FROM
ExhibitorsSearc hByName
//this query requires three parameters, Start_Date, End_Date, Event_ID
GROUP BY
ID, First(Company_N ame), First(level), First(QueryNbr)
WHERE
Company_Name LIKE '%myCriteria'

What would be the best way to execute the previous query in ASP, including
sending the appropriate parameters???

Sample code would be great!

Cheers,
Adam

Jul 17 '06 #1
1 1447
AJ wrote:
Folllowing on from a previous post, i have created a stored query as
follows.
Is this SQL Server or Access? ... OK, I just found your previous post and
discovered that this is Access.

I'm a little surprised it's allowing the @ symbol in your parameter names
.... I'm assuming you tested this and it works correctly in Access.
>
<snip>
I want use the results from the preceding query in the following way:

Did you try running the following query? It should not have worked as
written.
>
SELECT
ID, Company_Name, level, QueryNbr
FROM
ExhibitorsSearc hByName
//this query requires three parameters, Start_Date, End_Date,
Event_ID
GROUP BY
ID, First(Company_N ame), First(level), First(QueryNbr)
WHERE
Company_Name LIKE '%myCriteria'
The '%myCriteria should also be a parameter.
The WHERE clause (which should really come _before_ the GROUP BY clause if
you were going to keep using the WHERE clause) needs to be a HAVING clause,
because you are filtering by the result of an aggregate function that
provides a result _after_ the grouping is done.
The GROUP BY is strange. I think you want the aggregates in the Select
statement, don't you? Like this:
SELECT
ID,
First(Company_N ame) As Company_Name,
First(level) As level,
First(QueryNbr) As QueryNbr
FROM
ExhibitorsSearc hByName
GROUP BY
ID
HAVING
First(Company_N ame) LIKE [@myCriteria]
Test this query in Access before attempting to run it in ASP!!!

I would save this query as well - call it "ExhibitorsForS pecifiedCompany ".
When you test it, take note of the order in which Access prompts you for
parameter values. You will need to supply the values in the same order when
executing it from ASP.
>
What would be the best way to execute the previous query in ASP,
including sending the appropriate parameters???

Sample code would be great!
This is air code so it's untested:

Dim cn, rs, sDate, eDate, Event_ID, criteria
sDate=#2006-7-1#
eDate=#2006-7-31#
Event_ID = 28
criteria="%crit eria"

set cn=createobject ("adodb.connect ion")
cn.open "provider=micro soft.jet.oledb. 4.0;" & _
"data source=p:\ath\t o\db.mdb"
set rs=createobject ("adodb.records et")

'This is my guess as to the parameter order. Modify if your testing
'shows the order is different:

cn.ExhibitorsFo rSpecifiedCompa ny Event_ID,sDate, _
eDate, criteria, rs

if not rs.eof then ...

Bob Barrows

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 17 '06 #2

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

Similar topics

3
22152
by: dinesh prasad | last post by:
I'm trying to use a servlet to process a form, then send that data to an SQL server stored procedure. I'm using the WebLogic 8 App. server. I am able to retrieve database information, so I know my application server can talk to the database. I've determined the failure occurs when the the following statement is executed: cstmt.execute(); (due to the failure of println statements placed afterwards). I get the following error after trying to...
15
6022
by: Jarrod Morrison | last post by:
Hi All Im generally a vb programmer and am used to referencing multiple records returned from a query performed on an sql database and im trying to move some functions of my software into sql stored procedures. So far ive been able to move the functions relatively easily but im unsure about how to output multiple values from an sql stored procedure. By this i mean for example one of the stored procedures may take your username and return...
0
6708
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft Visual Basic .NET version of this article, see 308049. For a Microsoft Visual C++ .NET version of this article, see 310071. For a Microsoft Visual J# .NET version of this article, see 320627. This article refers to the following Microsoft .NET...
2
5465
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
45
3426
by: John | last post by:
Hi When developing vb.bet winform apps bound to sql server datasource, is it preferable to use SELECTs or stored procedure to read and write data from/to SQL Server? Why? Thanks Regards
0
2026
by: R L Vandaveer | last post by:
I am having an interesting and rather frustrating issue with the encoding/decoding of parameters with the ASP.NET runtime. What I am doing isn't exactly revolutionary so hopefully someone has an answer for this. I have a page that accepts a number of parameters. Those parameters may sometimes include URL reserved characters like spaces and ampersands. I use a combination of HTML and URL encoding to build links to this page and...
5
2363
by: ric_deez | last post by:
Hi there, I would like to create a simple search form to allow users to search for a job number based on a number of parameters. I think I understand how to use parameteres associated with Stored Procedures with a data reader to add various parameters. However, if I have a stored procedure such as CREATE usp_SelectfromJobNumbers (@par1 datatype, @par2 datatype, @par3 datatype)
6
6404
by: rn5a | last post by:
Suppose a SQL Server 2005 stored procedure looks like this: ALTER PROCEDURE SPName @UserID int SELECT COUNT(*) FROM Table1 WHERE UserID = @UserID SELECT COUNT(*) FROM Table1 In the ASPX page, I can get the result of the first query in the above SP using
9
2472
by: Frawls | last post by:
Hi I Am am having problems with a stored Procedure that i wrote. Basically whats happening is that the Stored procedure Runs fine when i EXECUTE it in SQL Query analyzer. But when i debug through the application in Visual Studio .NET 2003 the application an exception when it executes the query.
0
10838
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
10544
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...
1
10585
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10250
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9369
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...
0
5645
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...
0
5821
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4010
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3111
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.