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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:43:40+00:00 2026-05-22T19:43:40+00:00

I have an SP. It returns some number of rows. Here is the SP:

  • 0

I have an SP. It returns some number of rows. Here is the SP:

ALTER PROCEDURE [dbo].[spGetClients]

(
@orderBy varchar(50),
@startAge int,
@endAge int,
@sex char,
@staffId nvarchar(1024),
@statusId nvarchar(1024),
@ethnicityId nvarchar(1024),
@treatmentProviderId nvarchar(1024)
)
AS
BEGIN
SET NOCOUNT ON;

IF(@orderBy = 'Consumer Name')
BEGIN
    SELECT c.Id, dbo.GetClientFullName(c.FirstName, c.MiddleInit, c.LastName) AS ClientName, 
    c.DateOfBirth, dbo.GetAge(c.DateOfBirth, GETDATE()) AS Age, c.Sex, 
    dbo.GetClientStatus(c.Id, @statusId) AS Status, ca.Address, co.Phone, 
    dbo.GetEthnicity(c.Id, @ethnicityId) AS Ethnicity, dbo.GetDevelopmentalDisabilities(c.Id) AS Disabilities, 
    dbo.GetClientStaffContacts(c.Id, @staffId) AS Staff, dbo.GetClientContacts(c.Id) AS Contact, 
    dbo.GetClientInsuranceProviders(c.Id) AS HealthProvider, 
    dbo.GetClientTreatmentProviders(c.Id, @treatmentProviderId) AS TreatmentProvider
    FROM Client c  
    LEFT OUTER JOIN(        
        SELECT ca.ParentEntityId, ca.Address
        FROM ContactAddress ca
        INNER JOIN EntityName en ON en.Id = ca.EntityNameId AND en.Name = 'Client' 
        INNER JOIN GeneralLookup gl ON ca.glAddressTypeId = gl.Id AND gl.LookupItem = 'Primary'    
    ) ca ON c.Id = ca.ParentEntityId 
    LEFT OUTER JOIN(        
        SELECT co.ParentEntityId, co.ContactData Phone
        FROM ContactOther co
        INNER JOIN EntityName en ON en.Id = co.EntityNameId AND en.Name = 'Client' 
        INNER JOIN GeneralLookup gl ON co.glContactTypeId = gl.Id AND gl.LookupItem = 'Home'    
    ) co ON c.Id = co.ParentEntityId 
    LEFT OUTER JOIN GeneralStatus gs on gs.Id = c.StatusId
    where gs.Name <> 'Deleted' 
    and (dbo.GetAge(c.DateOfBirth, GETDATE()) BETWEEN @startAge and @endAge)
    and ((@sex = 'M' and c.sex = 'M') or (@sex = 'F' and c.Sex = 'F') or (@sex = '' and (c.Sex in ('M', 'F', ''))))
    and dbo.GetClientStaffContacts(c.Id, @staffId) is not null
    and dbo.GetClientStaffContacts(c.Id, @staffId) is not null
    and dbo.GetClientStatus(c.Id, @statusId) is not null 
    and dbo.GetEthnicity(c.Id, @ethnicityId) is not null 
    and dbo.GetClientTreatmentProviders(c.Id, @treatmentProviderId) is not null
    ORDER BY ClientName
END
END

The UDFs(User defined functions) are dbo.GetClientStaffContacts(c.Id, @staffId) and other. They return some rows which are having null as well. That’s why I’m using last 5 statements in where clause so that only non null values can be collected. Everything is working fine but the problem is, I want this check of non null only when these variables are NOT empty string:

@staffId nvarchar(1024), 
@statusId nvarchar(1024), 
@ethnicityId nvarchar(1024), 
@treatmentProviderId nvarchar(1024)

How can I resolve this issue?
I want something like this:

If @staffId <> '' then dbo.GetClientStaffContacts(c.Id, @staffId) is not null

  • 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-22T19:43:41+00:00Added an answer on May 22, 2026 at 7:43 pm
     AND  ((@staffId = "") OR (dbo.GetClientStaffContacts(c.Id, @staffId) is not null))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a Blackberry 5.2 browser app. I have some JavaScriptthat returns some
I have a method which returns some xml in a memory stream private MemoryStream
i have a query that returns some users related to a specific user (Bob).
I have a LINQ query that returns some object like this... var query =
I have created a web service which returns some data and am trying to
So I have a $.post , that returns some json_encode($array); $array is one dimensional,
I have a hashtable . values() method returns values in some order different from
I have a function that returns json (networks_function.php builds up some arrays and encodes
I have a query that returns data with group category and some details like
I have a stored proc which unions some data and returns back. At max

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.