?
Solved

Executing Stored Procedure with date parameter

Posted on 2006-05-02
3
Medium Priority
?
315 Views
Last Modified: 2008-02-01
Hi,

I have written SP as:

Create PROCEDURE sp_rptBirthDayList(@strPredicate As Varchar(7500),@strOrderBy as varchar(1000),@StartDate as datetime,@EndDate as datetime)
AS
                 xxxxxxxxxxxxxxxxxxxxxxxxxxx

Now I want to run this SP through Query Analyzer and I do it as:

sp_rptBirthDayList '', ' Passengers.LastName ', Convert(datetime,'20/12/2005', 103), Convert(datetime,'09/01/2006',103)

This gives me error:
Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'Convert'.

I have many such SPs that take date as parameter. They run well through my .NET application. But when we try to run them through Query Analyzer, we always get this error. How do I pass date parameter?

Regards,
VJ
0
Comment
Question by:vj_mi
3 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 500 total points
ID: 16584590
Hi vj_mi,

Don't worry about converting it, use:

sp_rptBirthDayList '', ' Passengers.LastName ', '2005-12-20', '2006-01-09'

Tim Cottee
0
 
LVL 12

Expert Comment

by:ill
ID: 16584736
-- rem: function call is not allowed when calling SP in QA. Variables must be used, if needed.
declare @st_date datetime, @end_dt datetime
set @st_dt = Convert(datetime,'20/12/2005', 103)
set @end_dt =  Convert(datetime,'09/01/2006',103)
exec sp_rptBirthDayList '', ' Passengers.LastName ', @st_dt , @end_dt
0
 
LVL 13

Expert Comment

by:Atlanta_Mike
ID: 16585863
Very important... don't name your stored procedures sp anything. This notates the stored procedure as "special". What this means is when you run the stored procedure the query engine will first look in the system database for the procedure then elsewhere.

Unless you want to incur a performance hit... change your names.

0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Suggested Courses

862 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