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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:41:43+00:00 2026-06-12T09:41:43+00:00

Solution_id (Primary key, Int) Col1 (varchar) Col2 (varchar) Col3 (varchar) Col4 (varchar) Col5 (varchar)

  • 0
Solution_id (Primary key, Int)
Col1 (varchar)
Col2 (varchar)
Col3 (varchar)
Col4 (varchar)
Col5 (varchar)

I am writing a stored procedure 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 overwrite the attachment columns with null. I mean I need to use only those parameters which contains data.

For example, if the table has a row

[10, "aaa", "bbb", "efg", null, null] 

and the input parameters are

(10, null, null, "mno", "ddd", null) 

then after the update the row will become

[10, "aaa", "bbb", "mno", "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-06-12T09:41:45+00:00Added an answer on June 12, 2026 at 9:41 am

    Is this something like you’re after?

    UPDATE mytable
    SET Col1 = ISNULL(@Attached_File1, Col1),
        Col2 = ISNULL(@Attached_File2, Col2),
        Col3 = ISNULL(@Attached_File3, Col3),
        Col4 = ISNULL(@Attached_File4, Col4),
        Col5 = ISNULL(@Attached_File5, Col5)
    WHERE Solution_id = @Ticket_ID
    

    ISNULL takes two values, if the first one is not null then it is used, otherwise the 2nd value is used.

    See MSDN for more information on ISNULL


    Update

    I’ve just noticed your comment at the end, which talks about empty strings…

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

    In which case, you could do the following…

    UPDATE mytable
    SET Col1 = ISNULL(NULLIF(@Attached_File1,''), Col1),
        Col2 = ISNULL(NULLIF(@Attached_File2,''), Col2),
        Col3 = ISNULL(NULLIF(@Attached_File3,''), Col3),
        Col4 = ISNULL(NULLIF(@Attached_File4,''), Col4),
        Col5 = ISNULL(NULLIF(@Attached_File5,''), Col5)
    WHERE Solution_id = @Ticket_ID
    

    This uses the NULLIF statement which takes two values, if the first value is the same as the second value, then NULL is returned, otherwise it returns the first value.

    See MSDN for more information on NULLIF

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

Sidebar

Related Questions

I have three tables: table "package" ----------------------------------------------------- package_id int(10) primary key, auto-increment package_name varchar(255)
With this schema: create table object ( obj_id serial primary key, name varchar(80) not
Here is a simplified table structure: TABLE products ( product_id INT (primary key, auto_increment),
My table Sections (SQL Server) has ID as a primary key (int, identity) and
I have two tables as below: users -id (primary key, AUTO_INCREMENT) -username (varchar) -password
Suppose I have these tables create table bug ( id int primary key, name
the primary key column of type 'tinyint' cannot be generated by the server... This
I have a table in SQL Server with the following columns: id int (primary
How to set a composite primary key for a All in One approach (grid
This is my table definition: CREATE TABLE orders_total ( orders_total_id int unsigned NOT NULL

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.