Executing Stored Procedure with date parameter

Posted on 2006-05-02
Last Modified: 2008-02-01

I have written SP as:

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

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?

Question by:vj_mi
    LVL 44

    Accepted Solution

    Hi vj_mi,

    Don't worry about converting it, use:

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

    Tim Cottee
    LVL 12

    Expert Comment

    -- 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
    LVL 13

    Expert Comment

    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.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
    Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
    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.

    737 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

    22 Experts available now in Live!

    Get 1:1 Help Now