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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:20:06+00:00 2026-06-17T14:20:06+00:00

I have an SQL stored procedure which accepts a DateTime parameter which has a

  • 0

I have an SQL stored procedure which accepts a DateTime parameter which has a default value of NULL

@pmNext_Check_Date DATETIME=NULL

I want to use this parameter in 3 scenarios:

  1. If it’s NULL then don’t update any records
  2. If it’s got a date value then update all my records specified in my WHERE clause
  3. The problem one! Set all the date fields in my query to NULL for the records in my WHERE clause.

Here is the block of code within the SP that is causing me issues (the rest of the UPDATE statement is build elsewhere in the SP and works fine):

IF @pmNext_Check_Date IS NOT NULL
    IF @pmNext_Check_Date ='' --This is the bit that is causing me a problem. I just need to check for a empty date
        SET @sql = @sql + ' Next_Check_Date = NULL '
    ELSE
        SET @sql = @sql + ' Next_Check_Date = @pmNext_Check_Date '                    

SET @sql = @sql + ' WHERE ID IN (1, 2)'

So for example if I have the following 2 rows:

ID NextCheckDate

1 12/12/12

2 NULL

In scenario 1 I wouldn’t pass the parameter in as the procedure will use the default value and no dates will be updated.

In scenario 2 I pass in a date value and update both rows with the date value

In scenario 3 I want to update the date value on my rows to be null. The difference between scenario 1 & 3 is in scenario 3 the user will be choosing to set the date values to null.

So, I wanted to pass a blank date into the stored procedure. I’m doing this from C# and would like to do something like the following:

SqlParameter param = new SqlParameter("@pmNext_Check_Date", "");                            

This fails as the SP is expecting a DateTime.

So I want to be able to pass in a blank date and also how do I check this within the SP. The current check which is below doesn’t work:

IF @pmNext_Check_Date =''

Thanks in advance.
Hope this all makes sense.
I’m using C#4.0 and SQL 2008

  • 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-06-17T14:20:07+00:00Added an answer on June 17, 2026 at 2:20 pm

    There is no such thing as a “blank date”. You could use a well-known sentinel value (01 Jan for some arbitrary ancient year, for example), but null would be preferable. Note that to pass an explicit null via a parameter, you need:

    SqlParameter param = new SqlParameter("@pmNext_Check_Date", DBNull.Value);
    

    If that doesn’t have enough granularity, consider adding a separate boolean (bit) parameter (or similar) that clarifies what you want the sproc to do. Or: have multiple procs to do these different things.

    One useful sentinel value for SQL Server is January 1, 1753 (SQL Server’s minimum datetime value) – this can be produced in TSQL without string parsing as cast(-53690 as datetime).

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

Sidebar

Related Questions

Suppose I have a PL/SQL stored procedure as follows: PROCEDURE do_something(foo VARCHAR2 DEFAULT NULL)
I have written a SQL Server stored procedure that includes a DateTime parameter. This
SQL Server 2005. I have a stored procedure which accepts a few parameters that
I have a PL/SQL stored procedure inside which I want to run several updates,
I have a stored procedure in SQL Server 2005 which accepts few parameters of
I have a SQL server stored procedure which would accept date as input param
I have a messy stored procedure which uses dynamic sql. I can debug it
I have a stored procedure called WEB_SEL_SECURITY_QUESTIONS in my sql database which returns a
I have a stored procedure which executes some dynamic sql, shown below. I've tried
I have a stored procedure which returns a Dataset(Table) . How can I use

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.