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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:05:59+00:00 2026-05-14T01:05:59+00:00

I want to call this procedure that sends one value that can be NULL

  • 0

I want to call this procedure that sends one value that can be NULL or any int value.

SELECT DomainName, DomainCode FROM Tags.tblDomain WHERE SubDomainId =@SubDomainId

I simply want to use this single query rather than what i m doing right now in below given code.

I searched for this how could i do this then i got this Link.

According to this I have to set ANSI_NULLS OFF

I am not able to set this inside this procedure before executing my sql query and then reset it again after doing this.

ALTER PROCEDURE [Tags].[spOnlineTest_SubDomainSelect] 
    @SubDomainId INT
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
    -- Insert statements for procedure here
    IF @SubDomainId IS NULL
        SELECT DomainName, DomainCode FROM Tags.tblDomain WHERE SubDomainId IS NULL 
    ELSE
        SELECT DomainName, DomainCode FROM Tags.tblDomain WHERE SubDomainId =@SubDomainId
END

What will be the better practice to do deal with ANSI_NULLS or Using If Else

  • 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-14T01:05:59+00:00Added an answer on May 14, 2026 at 1:05 am

    SET ANSI_NULLS is ony defined at stored proc create time and cannot be set at run time.

    From CREATE PROC

    Using SET Options

    The Database Engine saves the settings
    of both SET QUOTED_IDENTIFIER and SET
    ANSI_NULLS when a Transact-SQL stored
    procedure is created or modified.
    These original settings are used when
    the stored procedure is executed.
    Therefore, any client session settings
    for SET QUOTED_IDENTIFIER and SET
    ANSI_NULLS are ignored when the stored
    procedure is running. Other SET
    options, such as SET ARITHABORT, SET
    ANSI_WARNINGS, or SET ANSI_PADDINGS
    are not saved when a stored procedure
    is created or modified. If the logic
    of the stored procedure depends on a
    particular setting, include a SET
    statement at the start of the
    procedure to guarantee the appropriate
    setting. When a SET statement is
    executed from a stored procedure, the
    setting remains in effect only until
    the stored procedure has finished
    running. The setting is then restored
    to the value the stored procedure had
    when it was called. This enables
    individual clients to set the options
    they want without affecting the logic
    of the stored procedure.

    The same applies to SET QUOTED_IDENTIFIER

    In this case, use IF ELSE because SET ANSI_NULLS will be ON in the future.

    Or Peter Lang’s suggestion.

    To be honest, expecting SubDomainId = @SubDomainId to work when @SubDomainId is NULL is not really correct usage of NULL…

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

Sidebar

Related Questions

My use case is this, I want to call out to a webservice and
This is similar to my previous posting. But this time I want to call
I've got a stored procedure (we'll call it A) that calls another stored procedure
I want to call a function from a .NET DLL (coded in C#) from
I want to call a web service, but I won't know the url till
I want to call a few static methods of a CPP class defined in
I want to call ShowDialog() when a keyboard hook event is triggered, but I'm
I want to call a c# function from my javascript function. I have a
I want to call my .NET code from unmanaged C++. My process entrypoint is
I want to call some RESTful web services from a J2ME client running on

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.