Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Executing a Stored Procedure with a DATE

Posted on 2006-11-14
3
Medium Priority
?
385 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 143

Expert Comment

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

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 375 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

715 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