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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:39:58+00:00 2026-06-06T16:39:58+00:00

I am going to be executing an Update stored procedure from .NET. I want

  • 0

I am going to be executing an Update stored procedure from .NET. I want the following logic in T-SQL, however I can’t seem to find out how this can be done.

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE sp_UpdateTable

    @TableID int,
    @StartTime1 datetime,
    @EndTime1 datetime

AS
BEGIN
    SET NOCOUNT ON;

    UPDATE [Table]
       SET [StartTime1] = WAS_PASSED_FROM_CODE(@StartTime1, @StartTime1, [StartTime1])
          ,[EndTime1]   = WAS_PASSED_FROM_CODE(@EndTime1,   @EndTime1,   [EndTime1])
    WHERE TableID = @TableID
END
GO

Okay, so what I am basically looking for is a way to determine whether the parameter was specified from code, (hence WAS_PASSED_FROM_CODE) if the parameter was specified from code, then update that column to the specified value, else, leave intact (update to existing value).

Is this possible?

Note that in this case it is valid for the code to pass NULL, in that case, the column should update to NULL.

  • 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-06T16:39:59+00:00Added an answer on June 6, 2026 at 4:39 pm

    Make your parameters default to NULL and then use ISNULL. If the parameter is not specified it will be NULL

    Edit: Given that NULL is a valid value, add two additional parameters to marked whether or not the date parameters are specified.

    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    
    CREATE PROCEDURE sp_UpdateTable
    
        @TableID int,
        @StartTime1 datetime,
        @StartTime1Specified BIT,
        @EndTime1 datetime,
        @EndTime1Specified BIT
    
    AS
    BEGIN
        SET NOCOUNT ON;
    
        UPDATE [Table]
           SET [StartTime1] = (CASE WHEN @StartTime1Specified = 1 THEN @StartTime1 ELSE [StartTime1] END)
              ,[EndTime1]   = (CASE WHEN @EndTime1Specified = 1 THEN @EndTime1 ELSE [EndTime1])
        WHERE TableID = @TableID
    END
    GO
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Going from the example given here... http://ericswann.org/blog/archive/2009/04/06/linq-to-sql-datacontext-provider-revisited.aspx I'm trying to use the datacontext between
When working with a BlockingQueue , i implemented the following logic to read from
Going through Javascript documentation, I found the following two functions on a Javascript object
Going mad now. I have a MVC solution that i've upgraded from MVC 1
I'm getting the following error: SystemStackError: stack level too deep when executing the following
I'm trying to debug a fairly complex stored procedure that joins across many tabls
Before running an Update statement in SQL Server Management Studio, I'd like to see
In my application, I am executing a bunch of SQL queries like a job
I have a form that is going to be executing a failry long running
This query is not executing, and I'm sure its going over the code, it

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.