How to Deal with SET ANSI_NULLS ON or OFF ?

Posted by Shantanu Gupta on Stack Overflow See other posts from Stack Overflow or by Shantanu Gupta
Published on 2010-03-20T10:07:28Z Indexed on 2010/03/20 10:11 UTC
Read the original article Hit count: 203

Filed under:
|
|
|

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

© Stack Overflow or respective owner

Related posts about tsql

Related posts about database