SQL Stored Procedures

Posted on 2011-05-05
Last Modified: 2012-05-11
I have a stored procedure that performs an insert into a single table and in the table are several date fields. In one database the sp inserts fine but in another database the same data will get kicked back for a "Syntax error converting datetime from character string." error because the incoming date columns are getting populated with  a formated date of "@glEffectiveDate = 'Feb 18 2011 12:00:00:000AM',". If I manually change the date to '02/18/2011' it works fine. I have tried to use the SET DATEFORMAT mdy but it doesnot seem to help.

What am I missing?
Question by:ccptechs
    LVL 32

    Expert Comment


    Try using the format YYYYMMDD

    Author Comment

    The Set DateFormat YYYYMMDD is invalid
    LVL 35

    Expert Comment

    by:David Todd

    Try using the format YYYYMMDD

    This is the format of the string you are attempting to convert to datetime, not what to set the dateformat to.

    I'd suggest leaving the dateformat alone and using the format parameter in convert()


    Accepted Solution

    The stored proc where actually slightly different between the two databases in that the on sp erroring out had the parameters as  "@glEffectiveDate = 'default'" and the sp that worked used "@glEffectiveDate = null". Once I changed the non-working sp it worked.

    LVL 7

    Expert Comment

    Use the following sample, it'll help ypi..
    SELECT @glEffectiveDate = CONVERT(DATETIME,'Feb 18 2011 12:00:00:000AM')

    Author Closing Comment

    found the solution and corrected

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
    In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    779 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

    16 Experts available now in Live!

    Get 1:1 Help Now