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 1108265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:03:23+00:00 2026-05-17T02:03:23+00:00

I have a stored procedure in SQL Server 2008 that will insert a record

  • 0

I have a stored procedure in SQL Server 2008 that will insert a record into a table.

The sproc looks similar to this:

    -- params
@f1 int, 
@f2 datetime = null, 
@f3 datetime,
@f4 bit = 0 

BEGIN
    INSERT INTO dbo.table
    (fields......)
    VALUES
    (@params.....)

    RETURN @@IDENTITY
END

Prior to running the INSERT statement, I would like to trap the datetime value of the f2 param. If f2 is not a valid date I would like to set it to null.

I’m fuzzy on the syntax on how to do this. I thought the following would suffice, but not so:

--params
@f1..
@f2..
...

IF(ISDATE(@f2) < 1)
SET @f2= NULL

BEGIN
 INSERT...
 ...
END

What is the syntax for trapping and resetting a param value prior to executing an INSERT?

By the way, the reason that led me to finding a solution to this problem is rooted in the fact that I’m passing a C# minimum date value of “1/1/0001” to SQLS which supports minimum date value of “1/1/1753”.

  • 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-17T02:03:24+00:00Added an answer on May 17, 2026 at 2:03 am

    Since @f2 is a datetime it will never hold an invalid date

    but just for fun, this is how you would check it

    IF ISDATE(@f2) =0
    SET @f2= NULL
    

    But like I said this can never be true, if you pass Jan 1 1600 to the proc it will blow up and never execute

    if you are on SQL Server 2008 you can use datetime2

    Here is an example if you can’t change the datetime column, you can still use datetime2 for checking

    declare @d datetime2
    select @d = '16000101'
    
    select @d,
        convert(varchar(8),@d,112),
        isdate(convert(varchar(8),@d,112))  -- not a valid datetime
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SQL Server 2008 database. This database has a stored procedure that
I have a stored procedure in SQL Server 2008 that consists of multple select
I have a stored procedure in SQL Server 2008 that I want to store
I have a stored procedure that retrieves sensitive information from an SQL Server 2008
I'm using SQL Server 2008 Express, and I have a stored procedure that do
We have a SQL Server 2008 database that has stored procedures to handle reads/writes/etc.
On my SQL Server 2008 I have a stored procedure with a large number
If i have a stored procedure or a trigger in Sql Server 2008, can
I am writing a stored procedure in SQL Server 2008. Here I have a
I'm using SQL Server 2008. I have an interesting scenario where a stored procedure

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.