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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:49:49+00:00 2026-06-06T09:49:49+00:00

Possible Duplicate: How to eliminate NULL fields in TSQL I am using SSMS 2008

  • 0

Possible Duplicate:
How to eliminate NULL fields in TSQL

I am using SSMS 2008 R2 and am developing a TSQL query. I want just 1 record / profile_name. Because some of these values are NULL, I am currently doing LEFT JOINS on most of the tables. But the problem with the LEFT JOINs is that now I get > 1 record for some profile_names!

But if I change this to INNER JOINs then some profile_names are excluded entirely because they have NULL values for these columns. How do I limit the query result to just one record / profile_name regardless of NULL values? And if there are non-NULL values then I want it to choose the record with non-NULL values. Here is initial query:

select distinct
        gp.group_profile_id,
        gp.profile_name,
        gp.license_number,
        gp.is_accepting,
        case when gp.is_accepting = 1 then 'Yes'
            when gp.is_accepting = 0 then 'No '
            end as is_accepting_placement,
        mo.profile_name as managing_office,
        regions.[region_description] as region,     
        pv.vendor_name,
        pv.id as vendor_id,
        at.description as applicant_type,
        dbo.GetGroupAddress(gp.group_profile_id, null, 0) as [Office Address],
        gsv.status_description
from  group_profile gp With (NoLock)
    inner join group_profile_type gpt With (NoLock) on gp.group_profile_type_id = gpt.group_profile_type_id and gpt.type_code = 'FOSTERHOME' and gp.agency_id = @agency_id and gp.is_deleted = 0
    inner join group_profile mo With (NoLock) on gp.managing_office_id = mo.group_profile_id
    left outer join payor_vendor pv With (NoLock) on gp.payor_vendor_id = pv.payor_vendor_id
    left outer join applicant_type at With (NoLock) on gp.applicant_type_id = at.applicant_type_id and at.is_foster_home = 1
    inner join group_status_view gsv With (NoLock) on gp.group_profile_id = gsv.group_profile_id and gsv.status_value = 'OPEN' and gsv.effective_date =  
    (Select max(b.effective_date) from  group_status_view b  With (NoLock)
    where gp.group_profile_id = b.group_profile_id)
    left outer join regions With (NoLock) on isnull(mo.regions_id, gp.regions_id) = regions.regions_id
    left join enrollment en on en.group_profile_id = gp.group_profile_id
    join event_log el on el.event_log_id = en.event_log_id
    left join people client on client.people_id = el.people_id

As you can see, the results of the above query is 1 row / profile_name:

group_profile_id    profile_name    license_number  is_accepting    is_accepting_placement  managing_office region  vendor_name vendor_id   applicant_type  Office Address  status_description  Cert Date2

But now watch what happens when I add in 2 LEFT JOINs and 1 additional column:

select distinct
        gp.group_profile_id,
        gp.profile_name,
        gp.license_number,
        gp.is_accepting,
        case when gp.is_accepting = 1 then 'Yes'
             when gp.is_accepting = 0 then 'No '
            end as is_accepting_placement,
        mo.profile_name as managing_office,
        regions.[region_description] as region,     
        pv.vendor_name,
        pv.id as vendor_id,
        at.description as applicant_type,
        dbo.GetGroupAddress(gp.group_profile_id, null, 0) as [Office Address],
        gsv.status_description,
            ri.[description] as race
from  group_profile gp With (NoLock)
    inner join group_profile_type gpt With (NoLock) on gp.group_profile_type_id = gpt.group_profile_type_id and gpt.type_code = 'FOSTERHOME' and gp.agency_id = @agency_id and gp.is_deleted = 0
    inner join group_profile mo With (NoLock) on gp.managing_office_id = mo.group_profile_id
    left outer join payor_vendor pv With (NoLock) on gp.payor_vendor_id = pv.payor_vendor_id
    left outer join applicant_type at With (NoLock) on gp.applicant_type_id = at.applicant_type_id and at.is_foster_home = 1
    inner join group_status_view gsv With (NoLock) on gp.group_profile_id = gsv.group_profile_id and gsv.status_value = 'OPEN' and gsv.effective_date =  
    (Select max(b.effective_date) from  group_status_view b  With (NoLock)
    where gp.group_profile_id = b.group_profile_id)
    left outer join regions With (NoLock) on isnull(mo.regions_id, gp.regions_id) = regions.regions_id
    left join enrollment en on en.group_profile_id = gp.group_profile_id
    join event_log el on el.event_log_id = en.event_log_id
    left join people client on client.people_id = el.people_id
    left join race With (NoLock) on el.people_id = race.people_id
    left join race_info ri with (nolock) on ri.race_info_id = race.race_info_id

The above query results in all of the same profile_names, but some with NULL race values:

group_profile_id    profile_name    license_number  is_accepting    is_accepting_placement  managing_office region  vendor_name vendor_id   applicant_type  Office Address  status_description  Cert Date2  race

Unfortunately it complicates matters that I need to join in 2 additional tables for this one additional field value (race). If I simply change the last two LEFT JOINs above to INNER JOINs then I eliminate the NULL rows above. But I also eliminate some of the profile_names:

group_profile_id    profile_name    license_number  is_accepting    is_accepting_placement  managing_office region  vendor_name vendor_id   applicant_type  Office Address  status_description  Cert Date2  race

Hopefully I have provided all of the details that you need for this question.

  • 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-06T09:49:52+00:00Added an answer on June 6, 2026 at 9:49 am

    Not the most elegant solution, but one that will work:

    select [stuff]
    from  group_profile gp With (NoLock) 
      inner join group_profile_type gpt With (NoLock) on gp.group_profile_type_id = gpt.group_profile_type_id and gpt.type_code = 'FOSTERHOME' and gp.agency_id = @agency_id and gp.is_deleted = 0 
      inner join group_profile mo With (NoLock) on gp.managing_office_id = mo.group_profile_id 
      join payor_vendor pv on ISNULL(gp.payor_vendor_id, 'THISVALUEWILLNEVEROCCUR') = ISNULL(pv.payor_vendor_id, 'THISVALUEWILLNEVEROCCUR')
    ...etc...
    

    Biggest issue with what I posted is that you’ll be doing a whole lot of table scans.

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

Sidebar

Related Questions

Possible Duplicate: eliminate unwanted output using awk and sed The following contents are there
Possible Duplicate: Should C++ eliminate header files? In languages like C# and Java there
Possible Duplicate: regex for URL including query string I have a text or message.
Possible Duplicate: How to remove a cookie by using Javascript? javascript:void(document.cookie=PREF=ID=20b6e4c2f44943bb:U=4bf292d46faad806:TM=1249677602:LM=1257919388:S=odm0Ys-53ZueXfZG;path=/; domain=.google.com); How to
Possible Duplicate: std::string and its automatic memory resizing I am just curious, how are
Possible Duplicate: how to delete a file? My application first reads the fields in
Possible Duplicate: Any chance to get unique records using Linq (C#)? using System; using
Possible Duplicate: Unload a module in Python After importing Numpy, lets say I want
Possible Duplicate: How to store an IP in mySQL I want to get the
Possible Duplicate: How do you send email from a Java app using Gmail? How

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.