Interview Questions Answers.ORG
Interviewer And Interviewee Guide
Interviews
Quizzes
Home
Quizzes
Interviews Databases Programming Interviews:BtrieveClipperData ModelingData StructuresDatabase AdministrationDatabase Administrator (DBA)Database AnalystDatabase DeveloperDB DevelopmentEDI/Data Integration ExpertFirebirdHierarchicalIBM DB2InformixJava DatabaseMariaDBMicrosoft Access DeveloperMongoDBMS SQL ServerMySQL ProgrammingNetworkNoSQLObject RelationalPostgrePostgreSQLProgressRDBMSRelationalSQLSQL AdministratorSQL and PL/SQLSQL Notification ServicesSQL server 2008SSRSStored ProcedureSybaseTeradata
Copyright © 2018. All Rights Reserved
MS SQL Server Interview Question:
What Happens If NULL Values Are Involved in Comparison Operations?
Submitted by: AdministratorIf NULL values are involved in comparison operations, the result will be Boolean NULL values. This behavior is very interesting because you would expect a comparison operation returns only one of the two values: TRUE and FALSE. But SQL Server may return you a third value: NULL.
The tutorial script below proves that "1>NULL" is not returning TRUE or FALSE. It is returning a third value, NULL:
IF 1>NULL PRINT '1>NULL is returning TRUE'
ELSE PRINT '1>NULL is not returning TRUE'
GO
1>NULL is not returning TRUE
IF NOT 1>NULL PRINT '1>NULL is returning FALSE'
ELSE PRINT '1>NULL is not returning FALSE'
GO
1>NULL is not returning FALSE
Another test proves that "'GGL'=NULL" is not returning TRUE or FALSE. It is returning a third value, NULL:
IF 'GGL'=NULL PRINT '''GGL''=NULL returns TRUE'
ELSE PRINT '''GGL''=NULL does not return TRUE'
GO
'GGL'=NULL does not return TRUE
IF NOT 'GGL'=NULL PRINT '''GGL''=NULL returns FALSE'
ELSE PRINT '''GGL''=NULL does not return FALSE'
GO
'GGL'=NULL does not return FALSE
Submitted by: Administrator
The tutorial script below proves that "1>NULL" is not returning TRUE or FALSE. It is returning a third value, NULL:
IF 1>NULL PRINT '1>NULL is returning TRUE'
ELSE PRINT '1>NULL is not returning TRUE'
GO
1>NULL is not returning TRUE
IF NOT 1>NULL PRINT '1>NULL is returning FALSE'
ELSE PRINT '1>NULL is not returning FALSE'
GO
1>NULL is not returning FALSE
Another test proves that "'GGL'=NULL" is not returning TRUE or FALSE. It is returning a third value, NULL:
IF 'GGL'=NULL PRINT '''GGL''=NULL returns TRUE'
ELSE PRINT '''GGL''=NULL does not return TRUE'
GO
'GGL'=NULL does not return TRUE
IF NOT 'GGL'=NULL PRINT '''GGL''=NULL returns FALSE'
ELSE PRINT '''GGL''=NULL does not return FALSE'
GO
'GGL'=NULL does not return FALSE
Submitted by: Administrator
Copyright 2007-2024 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.
https://InterviewQuestionsAnswers.ORG.