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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:33:56+00:00 2026-05-27T22:33:56+00:00

So FIELD2 can return 2 groups of fields concatenated as a single result depending

  • 0

So FIELD2 can return 2 groups of fields concatenated as a single result depending on the value of Mycondition.

My problem is only when Mycondition = 1

If MyCondition = 1 then I need to concatenate INT_FIELD_ONE + ‘A’ + INT_FIELD_TWO.

The concatenation is not the problem.

The problem is if INT_FIELD_ONE (is null) + ‘A’ + INT_FIELD_TWO (is null), then I have to return nothing.

My Replace command would work if both fields ONE and TWO are null. But if only 1 is NULL and the other is not the “A” gets deleted any way. The A needs to remain if 1 field is not null.

For Example:

NULL + ‘A’ + NULL = Nothing

NULL + ‘A’ + xxxx = Axxxx

xxxx + ‘A’ + NULL = xxxxA

Therefore I need to make a TSQL replace with a length constraint of result > 1

Any Ideas?

SELECT XXX,

CASE --Case Statement to Return Field2
         WHEN MyCondition = 1 THEN
       --Constraint on the Replace Starts Here
       REPLACE(
       Isnull(CAST(INT_FIELD_ONE AS VARCHAR), '') + 'A' +
       Isnull(CAST(INT_FIELD_TWO AS
                   VARCHAR), '')
         ,'A','')  
ELSE
        REPLACE(
        Coalesce(REPLACE(INT_FIELD_THREE, '', '-'), Isnull(INT_FIELD_THREE, '-'), INT_FIELD_THREE) +
                ' / ' + Coalesce(REPLACE(INT_FIELD_FOUR, '', '-'),
                        Isnull(INT_FIELD_FOUR, '-'), INT_FIELD_FOUR) + ' ', '- / - ',
        '')
END
AS FIELD2


FROM TABLEX
  • 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-27T22:33:57+00:00Added an answer on May 27, 2026 at 10:33 pm

    how about this?

    CASE WHEN MyCondition = 1 AND (INT_FIELD_ONE IS NOT NULL OR INT_FIELD_TWO IS NOT NULL) THEN concat..
         WHEN MyCondition = 1 THEN NULL -- at that point we know that both are null
         ELSE ... END
    

    Notice that now you don’t need the REPLACE function when you are doing the concat because you know for sure that one of your fields is not null

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

Sidebar

Related Questions

How can I get SQL Server to return the first value (any one, I
If I've got a table containing Field1 and Field2 can I generate a new
3 fields: FirstName, MiddleName, LastName Any field can be null, but I don't want
In Java, I use a class in which some fields can be null .
I have a div that contains 3 fields You can see the image here
Is it possible to return querysets that return only one object per foreign key?
How can I check a group of hidden fields for their values and if
I have the following setup: Tasks, Accounts and Groups tables. Tasks can be assigned
Can someone help me i need to sort this array: $report_fields['client_id'] = $row['client_id']; $report_fields['name']
How can I write code in View so as to access the groupby fields

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.