danakee
asked on
Syntax for Passing a Parameter to a Stored Procedure
I have created a simple stored procedure which requires a single parameter @LocationID. I am calling the stored procedure from a Crystal Report and attempting to pass the parameter but I am apparently doing something wrong.
This works: {call getbatches ('350')}
The string '350' is being passed and the report works fine
This does not work: {call getbatches (?@LocationID)}
It's probably just a syntax issue but I haven't had any luck with a number of different syntax variations.
My data source is ODBC, database is SQL2K and platform is Crystal Reports under VS.Net.
I have found this link which gets me close, but no cigar.
http://support.crystaldecisions.com/library/kbase/articles/c2010974.asp
Any help would be greatly appreciated.
Thanks,
Dana
This works: {call getbatches ('350')}
The string '350' is being passed and the report works fine
This does not work: {call getbatches (?@LocationID)}
It's probably just a syntax issue but I haven't had any luck with a number of different syntax variations.
My data source is ODBC, database is SQL2K and platform is Crystal Reports under VS.Net.
I have found this link which gets me close, but no cigar.
http://support.crystaldecisions.com/library/kbase/articles/c2010974.asp
Any help would be greatly appreciated.
Thanks,
Dana
ASKER
I tried both and each one gives me a 'Failed to open a rowset' error message in the designer. It seems as if the sp will only accept a literal value.
The parameter name in the stored procedure is @LocationID. My Crystal Report parameter name is @LocationID. This is referenced in the page header as ?@LocationID so that is how I was thinking it should be referenced in the command section.
Thanks,
Dana Kee
The parameter name in the stored procedure is @LocationID. My Crystal Report parameter name is @LocationID. This is referenced in the page header as ?@LocationID so that is how I was thinking it should be referenced in the command section.
Thanks,
Dana Kee
{call getbatches ('350')}
You might see if this syntax works:
exec getbatches ({?@LocationID})
The parameter field is referenced in CR by surrounding it with curly braces. The question mark indicates that it is a parameter.
What version of CR are you using, and where are you trying to call the stored procedure?
You might see if this syntax works:
exec getbatches ({?@LocationID})
The parameter field is referenced in CR by surrounding it with curly braces. The question mark indicates that it is a parameter.
What version of CR are you using, and where are you trying to call the stored procedure?
ASKER
Works: exec getbatches '350'
Doesn't work: exec getbatches ({?@LocationID})
Using Crystal Reports for Visual Studio .NET
Here is the stored procedure:
CREATE procedure dbo.GetBatches
@LocationID nvarchar(50)
as
select
BatchType,
LocationID,
VisitDate,
Override,
UserID,
BatchSchedule
from BatchQueue
where LocationID = @LocationID
I have entered the call to the sp manually in the designer. I am concerned that while in the designer after selecting the data source in the tree I only see tables and views not stored procedures. Is this normal behavior of the designer?
Thanks,
Dana
Stored Procedures don't show by default. Turn that option on in the settings/options screen.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
After reading your post I right clicked on the Details section of the report and selected Designer>Default Settings and under the Database tabe check Stored Procedure. I then removed the @LocationID parameter that I had manually created, refreshed the database view and low and behold the parameter re-appeared (inserted automatically by Crystal) and the report works great. Looks like I'm learning CR the hard way.
Thanks to all of you for your support.
Thanks to all of you for your support.
I have a same problem here - I have checked stored procedures form Designer->Default Settings->Database tab - and now when I Add stored procedure from Add/Remove Database, i get the following error -
Not supported
Details: ADO error code: 0x80040e14
Source: Microsoft OLE DB Provider for SQL Server
Description: Incorrect syntax near the keyword CONVERT
SQL State 42000
Native Error 156
Please help - i really need to sort it very quickly - Thanx
Not supported
Details: ADO error code: 0x80040e14
Source: Microsoft OLE DB Provider for SQL Server
Description: Incorrect syntax near the keyword CONVERT
SQL State 42000
Native Error 156
Please help - i really need to sort it very quickly - Thanx
It works fine with Integer type parameters but gives this error with datetime type parameters
mohabbataen
It is considered bad form to put your question in someone else's question, even if it is related. This is especially true after an answer has been selected and the question closed. Please open a new question.
It is considered bad form to put your question in someone else's question, even if it is related. This is especially true after an answer has been selected and the question closed. Please open a new question.
Or: {call getbatches ({@LocationID})} <- If LocationID is a Formula