472,792 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,792 software developers and data experts.

Search/ Stored Procedure.. Not Working

Hi, I'm sort of new to Stored Procedures; and I'm building a search
page where there are 9 parameters the user can put in; as little as
1, at most 9.. then it runs the Stored P and looks at the values.
I am using the COALESCE; to skips nulls,... but I'm still not getting
the right results.. either I get 0 or 4000..
CREATE PROCEDURE Sp_Search
(
@AcctNum varchar (100),
@CliId varchar (10),
@CLName varchar (25),
@CFName varchar (25),
@Foundation varchar (100),
@Custodian varchar (255),
@MMgr varchar (255),
@Advisor varchar (50),
@PA varchar (3),
@Status varchar (3),
@rc int output
)

AS
SELECT tblAccounts.ActAccountNum, tblAccounts.ActClientID,
tblMasterList.MstLName, tblMasterList.MstFName,
tblMasterList.MstFoundationName, tblManagerList.Manager,
tblMasterList.MstDTIARep, tblMasterList.MstReconAssignID,
tblAccounts.ActAcctStatus

FROM ((tblAccounts INNER JOIN tblManagerList ON
tblAccounts.ActMgrID = tblManagerList.MgrID) INNER JOIN
tblCustodian ON tblAccounts.ActCustID = tblCustodian.CustIDRSN)
INNER JOIN tblMasterList ON tblAccounts.ActClientID =
tblMasterList.MstClientID

WHERE tblAccounts.ActAccountNum = COALESCE(@AcctNum,
tblAccounts.ActAccountNum) AND
tblAccounts.ActClientID = COALESCE(@CliID,
tblAccounts.ActClientId) AND
tblMasterList.MstLname = COALESCE( @CLName,
tblMasterList.MstLName) AND
tblMasterList.MstFName = COALESCE(@CFName,
tblMasterList.MstFName) AND
tblMasterList.MstFoundationName = COALESCE(@Foundation,
tblMasterList.MstFoundationName) AND
tblCustodian.Custodian = COALESCE(@Custodian,
tblCustodian.Custodian) AnD
tblManagerList.Manager = COALESCE(@MMgr,
tblManagerList.Manager) AND
tblMasterlist.MstDTIARep = COALESCE(@Advisor,
tblMasterList.MstDTIARep) AND
tblMasterlist.MstReconAssignID =COALESCE( @PA,
tblMasterlist.MstReconAssignID) AND
tblAccounts.ActAcctStatus =COALESCE( @Status,
tblAccounts.ActAcctStatus)

SET @rc = @@ROWCOUNT
Return
GO

Not sure what is missing, but below is what the Query Analyzer comes
out with..

[code:1:0837109d5b]
EXEC @RC = [TrackingGenX2K].[dbo].[Sp_Search]
@AcctNum, @CliId, @CLName, @CFName, @Foundation, @Custodian, @MMgr,
@Advisor, @PA, @Status, @rc OUTPUT
DECLARE @PrnLine nvarchar(4000)
PRINT 'Stored Procedure: TrackingGenX2K.dbo.Sp_Search'
SELECT @PrnLine = ' Return Code = ' + CONVERT(nvarchar, @RC)
PRINT @PrnLine
PRINT ' Output Parameter(s): '
SELECT @PrnLine = ' @rc = ' + isnull( CONVERT(nvarchar,
@rc), '<NULL>' )
PRINT @PrnLine

[/code:1:0837109d5b]

There is also an error attached now:

[code:1:0837109d5b]
Server: Msg 134, Level 15, State 1, Line 13
The variable name '@rc' has already been declared. Variable names must
be unique within a query batch or stored procedure.
[/code:1:0837109d5b]

ANY help would be appreciated.. THANKS!!! :lol: :oops: :D
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Jul 21 '05 #1
1 1329
You may want to put this in microsoft.public.sqlserver.programming group

Chris
"Compkitty" <co********@yahoo-dot-com.no-spam.invalid> wrote in message
news:42********@127.0.0.1...
Hi, I'm sort of new to Stored Procedures; and I'm building a search
page where there are 9 parameters the user can put in; as little as
1, at most 9.. then it runs the Stored P and looks at the values.
I am using the COALESCE; to skips nulls,... but I'm still not getting
the right results.. either I get 0 or 4000..
CREATE PROCEDURE Sp_Search
(
@AcctNum varchar (100),
@CliId varchar (10),
@CLName varchar (25),
@CFName varchar (25),
@Foundation varchar (100),
@Custodian varchar (255),
@MMgr varchar (255),
@Advisor varchar (50),
@PA varchar (3),
@Status varchar (3),
@rc int output
)

AS
SELECT tblAccounts.ActAccountNum, tblAccounts.ActClientID,
tblMasterList.MstLName, tblMasterList.MstFName,
tblMasterList.MstFoundationName, tblManagerList.Manager,
tblMasterList.MstDTIARep, tblMasterList.MstReconAssignID,
tblAccounts.ActAcctStatus

FROM ((tblAccounts INNER JOIN tblManagerList ON
tblAccounts.ActMgrID = tblManagerList.MgrID) INNER JOIN
tblCustodian ON tblAccounts.ActCustID = tblCustodian.CustIDRSN)
INNER JOIN tblMasterList ON tblAccounts.ActClientID =
tblMasterList.MstClientID

WHERE tblAccounts.ActAccountNum = COALESCE(@AcctNum,
tblAccounts.ActAccountNum) AND
tblAccounts.ActClientID = COALESCE(@CliID,
tblAccounts.ActClientId) AND
tblMasterList.MstLname = COALESCE( @CLName,
tblMasterList.MstLName) AND
tblMasterList.MstFName = COALESCE(@CFName,
tblMasterList.MstFName) AND
tblMasterList.MstFoundationName = COALESCE(@Foundation,
tblMasterList.MstFoundationName) AND
tblCustodian.Custodian = COALESCE(@Custodian,
tblCustodian.Custodian) AnD
tblManagerList.Manager = COALESCE(@MMgr,
tblManagerList.Manager) AND
tblMasterlist.MstDTIARep = COALESCE(@Advisor,
tblMasterList.MstDTIARep) AND
tblMasterlist.MstReconAssignID =COALESCE( @PA,
tblMasterlist.MstReconAssignID) AND
tblAccounts.ActAcctStatus =COALESCE( @Status,
tblAccounts.ActAcctStatus)

SET @rc = @@ROWCOUNT
Return
GO

Not sure what is missing, but below is what the Query Analyzer comes
out with..

[code:1:0837109d5b]
EXEC @RC = [TrackingGenX2K].[dbo].[Sp_Search]
@AcctNum, @CliId, @CLName, @CFName, @Foundation, @Custodian, @MMgr,
@Advisor, @PA, @Status, @rc OUTPUT
DECLARE @PrnLine nvarchar(4000)
PRINT 'Stored Procedure: TrackingGenX2K.dbo.Sp_Search'
SELECT @PrnLine = ' Return Code = ' + CONVERT(nvarchar, @RC)
PRINT @PrnLine
PRINT ' Output Parameter(s): '
SELECT @PrnLine = ' @rc = ' + isnull( CONVERT(nvarchar,
@rc), '<NULL>' )
PRINT @PrnLine

[/code:1:0837109d5b]

There is also an error attached now:

[code:1:0837109d5b]
Server: Msg 134, Level 15, State 1, Line 13
The variable name '@rc' has already been declared. Variable names must
be unique within a query batch or stored procedure.
[/code:1:0837109d5b]

ANY help would be appreciated.. THANKS!!! :lol: :oops: :D
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Jul 21 '05 #2

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

Similar topics

0
by: todd | last post by:
here is a search tool SP I wrote. How many times have you wanted to search all your Stored procs or views (in a database) for a keyword but couldn't!? Well now you can! THis can makes life a...
3
by: rdlebreton | last post by:
Hello, I am looking for help with the following situation. I have created a simple call tracking system that is integrated with our accounting / warehousing program in the company. The call...
2
by: M Wells | last post by:
Hi All, I'm wondering if anyone can tell me if it's possible to search for stored procedures by their contents? I tend to leave very descriptive notes in stored procedures and they're...
3
by: Job Lot | last post by:
My DataGrid is bound to DataSet which contains relationship between two tables as follows: SqlHelper.FillDataset(strConn, CommandType.StoredProcedure, "spSelectClientApplicant", ds, New String()...
4
by: Axel | last post by:
Is it possible to write a Stored Procedure that takes a string of search keywords as argument and returns the recordset? At the mo I am passing the WHERE String as argument. I got this...
1
by: Compkitty | last post by:
Hi, I'm sort of new to Stored Procedures; and I'm building a search page where there are 9 parameters the user can put in; as little as 1, at most 9.. then it runs the Stored P and looks at the...
25
by: abbylee26 | last post by:
my page works fine if the db search finds at least one record that satifies the query. but if it does not find a match I get the following error message. Error Type: ADODB.Field (0x80020009)...
4
by: red vertigo | last post by:
HI All, Can't quite get my head aorund this problem. My knowledge or more importantly my experience of using T-SQL is small and as a consequence my stored procedures are basic. My current...
2
by: acw | last post by:
On a SQL Server 2000 db I would like to setup a stored procedure that accesses couple tables and runs the extended stored procedure xp..cmdshell. The goal is to grant users with limited privileges...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 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...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 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...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
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=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.