Solved

Executing a Stored Procedure with a DATE

Posted on 2006-11-14
3
319 Views
Last Modified: 2008-02-26
Hi,

I've got a stored procedure:

CREATE PROCEDURE TestTable.spTest
      @StartDateGreaterThan SMALLDATETIME,
      @StartDateLessThan SMALLDATETIME
AS
   SELECT * FROM TestTable
   WHERE StartDate > @StartDateGreaterThan AND StartDate < @StartDateLessThan

When I try to execute it, via:

EXECUTE TestTable.spTest 1-1-1900, 1-1-2100

I get:

Incorrect syntax near '-'.

Here's what else I've tried:

EXECUTE TestTable.spTest '1-1-1900', '1-1-2100'
-> Error converting data type varchar to smalldatetime.
EXECUTE TestTable.spTest #1-1-1900#, #1-1-2100#
-> Incorrect syntax near '-'.
EXECUTE TestTable.spTest '1/1/1900', '1/1/2100'
-> Error converting data type varchar to smalldatetime.
EXECUTE TestTable.spTest 1/1/1900, 1/1/2100
-> Incorrect syntax near '/'.


What is the correct way to call this stored procedure?
0
Comment
Question by:CMES-IT
  • 2
3 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17941108
EXECUTE TestTable.spTest '1900-01-01', '2100-01-01'
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 125 total points
ID: 17941114
or, the professional way:

DECLARE @s datetime
DECLARE @e datetime
SET @s = CONVERT(datetime, '1900-01-01', 120)
SET @e = CONVERT(datetime, '2100-01-01', 120)

EXECUTE TestTable.spTest @s, @e
0
 

Author Comment

by:CMES-IT
ID: 17941165
Hi Angel,

Thanks,

This:
EXECUTE TestTable.spTest '1900-01-01', '2100-01-01'
Produces: Error converting data type varchar to smalldatetime.

And This:

DECLARE @s datetime
DECLARE @e datetime
SET @s = CONVERT(datetime, '1900-01-01', 120)
SET @e = CONVERT(datetime, '2100-01-01', 120)

EXECUTE TestTable.spTest @s, @e

Produces:
Error converting data type varchar to smalldatetime.

However, that second one got me on the right track.

The correct syntax is:

DECLARE @s smalldatetime
DECLARE @e smalldatetime
SET @s = CONVERT(smalldatetime, '1950-01-01', 120)
SET @e = CONVERT(smalldatetime, '2050-01-01', 120)

EXECUTE Accounting.spAccountCodeTest @s, @e

That works!

Thanks for getting me on the right track ;)

0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
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 videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

757 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