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

The Archive Base Latest Questions

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

I have a multiple fields that needs to be put into a string only

  • 0

I have a multiple fields that needs to be put into a string only when there is something in the field and on top of that I don’t want the commas between fields if they are null. I tried using case when but am clearly doing something wrong and would appreciate some help with the following:

USE newCityCollection

UPDATE PropertyInformationDump
SET    RegistryAdd = (CASE
                        WHEN b.OCAREOF IS NULL THEN Isnull(b.OCAREOF, '')
                        ELSE b.OCAREOF + ' ,'
                      END) + (CASE
                                WHEN b.O1STADD IS NULL THEN Isnull(b.O1STADD, '')
                                ELSE b.O1STADD + ' ,'
                              END) + (CASE
                                        WHEN b.O2NDADD IS NULL THEN Isnull(b.O2NDADD, '')
                                        ELSE b.O2NDADD + ' ,'
                                      END) + (CASE
                                                WHEN b.OSTNAME IS NULL THEN Isnull(b.OSTNAME, '')
                                                ELSE b.OSTNAME + ' ,'
                                              END) + (CASE
                                                        WHEN b.OCITYST IS NULL THEN Isnull(b.OCITYST, '')
                                                        ELSE b.OCITYST + ' ,'
                                                      END) + (CASE
                                                                WHEN b.OZIP IS NULL THEN Isnull(b.OZIP, '')
                                                                ELSE b.OZIP + ' ,'
                                                              END)
FROM   dbo.vw_BRT b
WHERE  BRTNumber = b.PARCEL

When I execute that on a field I get nada and am not sure why which is likely a fundemental misunderstanding of how CASE works. I did make sure those fields were actually null and not empty so that is not the problem.

  • 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-17T09:41:04+00:00Added an answer on June 17, 2026 at 9:41 am

    Consider the following: when you join strings together in SQL, and one of them is null, the result is null(*). So, if you add the comma before eliminating nulls, it’s a tad easier:

    SELECT COALESCE(b.OCAREOF + ' ,','') + COALESCE(b.O1STADD + ' ,','') + ...
    

    No CASE needed here.

    COALESCE is similar to ISNULL and would usually be recommended except for a few odd situations – for one, it’s part of standard SQL (useful if you ever have to work against other RDBMSes), for another it can accept multiple arguments and returns the first non-NULL one. For a third, it uses the most appropriate data type for the result considering the types of each expression – ISNULL always tries to convert the second argument to the type of the first)


    (I’m also not sure what you we’re doing in your CASE expressions – you’d already established that, e.g. OCAREOF was null – there was no need to then use an ISNULL expression to obtain '')


    (*) As Conrad points out, on SQL Server this does depend on CONCAT_NULL_YIELDS_NULL being ON, but it is by default and it really should be:

    In a future version of SQL Server CONCAT_NULL_YIELDS_NULL will always be ON and any applications that explicitly set the option to OFF will generate an error. Avoid using this feature in new development work, and plan to modify applications that currently use this feature.

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

Sidebar

Related Questions

I have a an image of a text field that I want to put
I have a Custom Control that has multiple textbox fields and a checkbox contained
I have a report that is basically a form with multiple empty fields and
I have an application that allows the user to edit multiple text fields and
I have a table that has multiple rows with the following fields: PersonName SongName
I have a table that contains members names and a field with multiple ID
I am creating a form that needs to have 30 or more fields either
I have two fields that need to multiply each other and fill a third
I have multiple fields for social networking websites where users can enter their username
I have multiple input fields on my page. I Regex them with a css

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.