Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6053427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:02:21+00:00 2026-05-23T08:02:21+00:00

Maybe I’m being an idiot here, but I’m trying to assign a default DateTime

  • 0

Maybe I’m being an idiot here, but I’m trying to assign a default DateTime value to a Stored Procedure in MS SQL Server 2005 but can’t get it to work eg:

CREATE PROCEDURE MyProcedure
(
    @MyInteger    INT = 123,
    @MyDateTime   DATETIME = CONVERT(DATETIME, '1753-01-01 00:00:00', 20)
)
AS
BEGIN ... (snip)

So if the @MyDateTime input parameter isn’t specified, it should use ‘1753-01-01 00:00:00’ by default, but I get the error…

Incorrect syntax near the keyword 'CONVERT'.

I can get it to work for Integers just fine. What am I doing wrong?


Edit: from the answers below, I eventually went with the following inside the Sproc itself:

CREATE PROCEDURE MyProcedure
(
    @MyInteger    INT = 123,
    @MyDateTime   DATETIME = NULL
)
AS
BEGIN
    SET NOCOUNT ON

    SET @MyDateTime = COALESCE(@MyDateTime, CONVERT(DATETIME, '1753-01-01 00:00:00', 20))

    ...snip...
END
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:02:22+00:00Added an answer on May 23, 2026 at 8:02 am

    @MyDateTime DATETIME ='1753-01-01 00:00:00'

    Or right within the sproc you can do this:

    SELECT @MyDateTime = (SELECT CONVERT(DATETIME, '1753-01-01 00:00:00', 20))

    The error is due to calling CONVERT, which you cannot do when defaulting parameters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

maybe I am being stooped... but the fact is that I am a bit
Maybe it has been asked somewhere, but I am trying to find my question
Maybe I'm an idiot but I don't quite get what goes in the header
maybe this is an old question but i'm trying as a personal experiment to
Maybe I am being stupid, but this isn't making sense to me... I have
Maybe a silly question but here goes anyway. Example: Let's say I have one
Maybe this has already been answered and I am searching incorrectly, but here is
Maybe a silly question but where/how should I define default values for GORM domain
Maybe I just don't know .NET well enough yet, but I have yet to
Maybe the need to do this is a 'design smell' but thinking about another

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.