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

  • SEARCH
  • Home
  • 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 7681879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:26:32+00:00 2026-05-31T18:26:32+00:00

I have a table which has the below columns. Ticket_id (Primary key, Int) Attachment1

  • 0

I have a table which has the below columns.

Ticket_id (Primary key, Int)
Attachment1 (varchar)
Attachment2 (varchar)
Attachment3 (varchar)
Attachment4 (varchar)
Attachment5 (varchar)

I am writing a stored proc to update this table. there are 6 input parameters for the above 6 columns.

@Attached_File1 VARCHAR(MAX),
@Attached_File2 VARCHAR(MAX),
@Attached_File3 VARCHAR(MAX),
@Attached_File4 VARCHAR(MAX),
@Attached_File5 VARCHAR(MAX),
@Ticket_ID BIGINT

I want to write a sql query which will update the table with the values specified in the input parameters. BUT I must not overrite the attachment columns with null. I mean I need to use only those parameters which contains data.

For example, if the table ha a row [10, “aaa”, “bbb”, null, null, null] and the input parameters are (10, null, null, “ccc”, “ddd”, null) then after the update the row will become [10, “aaa”, “bbb”, “ccc”, “ddd”, null]

How to check for null/empty strings and generate the update query accordingly to achieve this?

  • 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-31T18:26:33+00:00Added an answer on May 31, 2026 at 6:26 pm

    You can use ISNULL

    UPDATE table_name SET
      Attachment1 = ISNULL(Attachment1, @Attached_File1),
      Attachment2 = ISNULL(Attachment2, @Attached_File2),
      Attachment3 = ISNULL(Attachment3, @Attached_File3),
      Attachment4 = ISNULL(Attachment4, @Attached_File4),
      Attachment5 = ISNULL(Attachment5, @Attached_File5)
    WHERE Ticket_id = @Ticket_ID
    

    This solution does not overwrite an existing value with a new. If you want to do that, you should switch the values around:

    ISNULL(@Attached_File1, Attachment1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table which has two varchar(Max) columns Column 1 Column 2 -----------------------
if i have a table which has columns with fixed lenght, Will mySQL count
I have a consumer table which has the columns - Email, AccountState and DateCreated
I have a table called Task which has, among others, two columns: Date_due: a
I have a table which has several one to many relationships with other tables.
I have a table which has two text boxes and an image beside it
I have a table which has employee relationship defined within itself. i.e. EmpID Name
I have a table which has essentially boolean values in a legacy database. The
I have a table which has a column called Direct of type char(1). It's
I have a table which has a NVARCHAR column, which could contain a GUID

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.