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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:12:06+00:00 2026-05-23T17:12:06+00:00

So if my store procedure is called with a null item I want to

  • 0

So if my store procedure is called with a null item I want to make it ” (otherwise it won’t work with my result list)
How does one do this?

I would like my code to spit out the population for one country if the country input was US,null,null, or I want it more specific population if US,New York, New York City is put in. So population of New York City.

Create procedure [dbo].[GetPopulation]

        @CountryCode varchar(3),
    @State varchar(80)=null,
    @City varchar(80)=null
as
if @State is Null 
    @State = ''
if @City is Null 
    @City = ''

select Population
FROM Countries
Where CountryCode = @CountryCode AND State = @State AND City=@City
  • 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-23T17:12:06+00:00Added an answer on May 23, 2026 at 5:12 pm

    If I am right you want to ignore where clause’s when parameter is null

    select Population
    FROM Countries
    Where (CountryCode = @CountryCode OR @CountryCode IS NULL)
     AND (State = @State OR @State IS NULL)
     AND (City=@City OR @City IS NULL)
    

    In case your problem is the application parameters the procedure run’s with, then default param’s to ”

    Create procedure [dbo].[GetPopulation]
    
            @CountryCode varchar(3),
        @State varchar(80)='',
        @City varchar(80)=''
    
    select Population
    FROM Countries
    Where CountryCode = @CountryCode AND State = @State AND City=@City
    

    Run the procedure as dbo.GetPopulation 'US' for US or

    dbo.GetPopulation 'US','New York', 'New York City' for New York City
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a somewhat-long-running stored procedure being called from a PB application. I want
I want to make a Stored Procedure that has a minimum of 2 required
I have a variable called $result which should store all the results from my
I have a stored procedure called sp_BulkInsert that inserts one .csv file into my
I have a Stored Procedure called spGetOrders which accepts a few parameters: @startdate and
So I have a stored procedure called Spr_EventLogCreate defined in my database. I have
I have a stored procedure called WEB_SEL_SECURITY_QUESTIONS in my sql database which returns a
My stored procedure is called as below from an SQL instegartion package within SQL
I have a stored procedure which is called inside a trigger on Insert/Update/Delete. The
Within a stored procedure, another stored procedure is being called within a cursor. For

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.