April 24, 2008 at 7:02 am
Gila,
it's simply going to evaluate it as a scalar value.
what it means ?
karthik
April 24, 2008 at 7:11 am
Scalar = single value
Hence, the where clause you had (@Nm IS NULL) is a scalar (single value) evaluation, because it's a single value (the contents of the variable) been compared with a single value (NULL)
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
April 24, 2008 at 7:18 am
Yes.
what will happen internally is
Declare @Nm varchar(25)
select @Nm = 'Age'
select @Null = count(*) from #t1 where @Nm is null
it means select @Null = count(*) from #t1 where Age is null. do u agree till this point ?
But after that, why it is not storing 3 in @Null variable. Please correct me if i am wrong.
My question is:
count(*) from #t1 where Age is null whether it will be executed by sql analyzer or not. If not why ?
karthik
April 24, 2008 at 10:08 am
karthikeyan (4/24/2008)
I would like to add some more things.if i execute the below one, it is giving 3 as the output.
Declare @Nm varchar(25),@Null int
--select @Nm = 'Age'
select @Null = count(*) from #t1 where age is null
select @Null
So - it sounds like you have your answer, or not?
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
April 24, 2008 at 12:28 pm
karthikeyan (4/24/2008)
Yes.what will happen internally is
Declare @Nm varchar(25)
select @Nm = 'Age'
select @Null = count(*) from #t1 where @Nm is null
it means select @Null = count(*) from #t1 where Age is null. do u agree till this point ?
But after that, why it is not storing 3 in @Null variable. Please correct me if i am wrong.
My question is:
count(*) from #t1 where Age is null whether it will be executed by sql analyzer or not. If not why ?
this
Declare @Nm varchar(25)
select @Nm = 'Age'
select @Null = count(*) from #t1 where @Nm is null
becomes
select @Null = count(*) from #t1 where 'Age' is null
'Age' is not null, it is 'Age'
you can't pass a column as a variable unless you use dynamic SQL
Sorry if this has already been discussed, I only read the last few entries:)
April 24, 2008 at 11:40 pm
karthikeyan (4/24/2008)
it means select @Null = count(*) from #t1 where Age is null. do u agree till this point ?
No!
It means
select @Null = count(*) from #t1 where 'Age' is null
Not Age as a column name, 'Age' as a string literal. Which IS NOT NULL
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
April 25, 2008 at 3:05 am
What part don't you understand?
When SQL uses a variable in a where clause it uses the contents of the variable as a literal value. Not as a reference to a table/column/database/any other object.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
April 25, 2008 at 3:29 am
When SQL uses a variable in a where clause it uses the contents of the variable as a literal value. Not as a reference to a table/column/database/any other object.
This is what i expect. Now i am clear.
Thanks a lot Gila !
karthik
Viewing 10 posts - 16 through 25 (of 25 total)
You must be logged in to reply to this topic. Login to reply