tags:

views:

104

answers:

4

Hi,I have wriiten a part of code for you and I want to know the output ,I need your help because there is not any body for helping me also I think that the out put is A ,is this correct? thanks.

declare @v1 varchar(20),@v2 varchar(20)
select @v1 = 'NULL'
if @v1 is null and @v2 is null
select 'A'
else
select 'B'

EDITED: also what is the value of @ v2 ? thanks

A: 

I'd say it's B because = NULL and = 'NULL' are two different things.

Kamil Szot
+5  A: 

Why don't you try it yourself?

The output will be B because @v1 is assigned a string 'NULL' which is not the same as the special NULL meaning "no value"

Anders Abel
+1 That is my answer too.
Will Marcouiller
+1  A: 

In MSSQL 2008 it returns B. That is because @v1 is the string 'NULL', and not actually null. If you change it to

select @v1 = null

Then it will return A

Nelson
what is the value of @v2 ?
Since no value has been assigned to it (it was only declared), the value of @v2 is null. So come to think of it, the "select @v1 = null" is really redundant, since it's already null to start with.
Nelson
A: 

@v2 is null, since you do not assing any value to it. The output is B ´cause NULL is not the same as the string 'NULL'

Claudia