DateTime parmater for sp and debug

  • I have a SP that uses a input dateTime paramater. Does anyone happen to know what the proper format is to enter this paramater when using the T-SQL Debugger. I keep getting an invalid character value for cast specification on the different formats I have tried.

  • Can you provide an example of the TSQL code you are using when calling the SP?



    Once you understand the BITs, all the pieces come together

  • Not a problem when actually calling - just trying to use with T-SQL debugger and setting input paramaters. I have tried entering date as mm/dd/yyyy mm:hh:ss and different variations - but keep getting the inavlaid character in cast whenever I execute the sp with the debugger tool. The paramater list looks like this -

    proc sp_segmentCount

    @companyNum nvarchar (6),

    @campaignID nvarchar (16),

    @segmentID nvarchar (16),

    @endRunDate datetime

  • have you tried putting single quotes around the value? i.e. 'mm/dd/yyyy mm:hh:ss'



    Once you understand the BITs, all the pieces come together

  • Yes - I have tried entering -

    '12/18/2003 10:30:00', with and without time, single quotes etc. Must be something basic here, just not sure what it is. As a temporary fix to get around it and changed paramater to nvarchar and then do a cast to datetime - which does work.

  • I'm glad you got something to work. Let us know if you find out how to pass dates in the debugger.



    Once you understand the BITs, all the pieces come together

  • Have you tried the format:

    'yyyy-mm-dd hh:mm:ss'

    i.e. '2003-12-18 18:30:00'

    -SQLBill

  • I have found out that SQL Server does a correct implicit conversion from varchar to datetime if you use XML date format:

    'yyyy-mm-ddThh:mm:ss' (note the letter T between date and time part)

    I use it to fill datetime parameter of stored procedure. Works every time no matter what your regional settings, language or dateformat settings are.

    I haven't tried on a debugger yet, tell me if it works.

    Edited by - jcool on 12/19/2003 01:09:59 AM

  • You need to use the following ANSI formats (including the curly brackets):

    { d 'yyyy-mm-ddd'} for date only

    { ts 'yyyy-mm-dd hh:mm:ss'} for date and time

    I've been through the same hoops as you - it took me ages to find this in BOL.

    Have a look at 'Rules for Entering Search Values' in BOL.

  • These are the formats the seem to work just fine when entering the parmaters in T-SQL debugger -

    { d 'yyyy-mm-ddd'} for date only

    { ts 'yyyy-mm-dd hh:mm:ss'} for date and time

    Thanks as this would have taken forever to find, you would think there would be a little better documentation on this.

Viewing 10 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic. Login to reply