Solved

Syntax for Passing a Parameter to a Stored Procedure

Posted on 2003-12-10
11
3,115 Views
Last Modified: 2008-03-17
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
0
Comment
Question by:danakee
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 42

Expert Comment

by:frodoman
ID: 9915698
Try: {call getbatches ({?LocationID})}  <- If LocationID is a Parameter

Or: {call getbatches ({@LocationID})}  <- If LocationID is a Formula
0
 

Author Comment

by:danakee
ID: 9916427
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
0
 
LVL 13

Expert Comment

by:EwaldL
ID: 9916718
0
 
LVL 12

Expert Comment

by:DRRYAN3
ID: 9918126
{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?
0
 

Author Comment

by:danakee
ID: 9918417

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
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 12

Expert Comment

by:DRRYAN3
ID: 9919917
Stored Procedures don't show by default.  Turn that option on in the settings/options screen.

0
 
LVL 12

Accepted Solution

by:
DRRYAN3 earned 500 total points
ID: 9920747
Are you trying to base your report on a stored procedure instead of a table or view?  If so, when you choose your data source (after turning on the option to show stored procedures), Crystal Reports will examine the stored procedure to determine all parameters.  Previewing the report or refreshing the data will execute the report and all parameters will be populated in the stored procedure.
0
 

Author Comment

by:danakee
ID: 9921814
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.
0
 

Expert Comment

by:mohabbataen
ID: 10079592
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
0
 

Expert Comment

by:mohabbataen
ID: 10079753
It works fine with Integer type parameters but gives this error with datetime type parameters
0
 
LVL 12

Expert Comment

by:DRRYAN3
ID: 10081166
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now