Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Can any one Explain

Author  Topic 

khalik
Constraint Violating Yak Guru

443 Posts

Posted - 2002-07-23 : 04:23:11

thanks a lot for look in... i have a example u ca paste and see it returns different data... bit not clear

 

create table #abc(a numeric,b varchar(5),c varchar(10))
insert into #abc values (1,'aa1','a11a3sas')
insert into #abc values (1,'aa2','a11a1sas')
insert into #abc values (2,'aa3','a11a4sas')
insert into #abc values (3,'aa4','a11a6sas')
insert into #abc values (1,'aa3','a11a3sas')

declare @a numeric,@b varchar(5),@c varchar(10)
begin
select @a=a,@b=b,@c=c from #abc where a=1 order by 2 desc
select @a,@b,@c
select a, b,c from #abc where a=1 order by 2 desc

select @a=a,@b=b,@c=c from #abc where a=1
select @a,@b,@c
select a, b,c from #abc where a=1

select top 1 @a=a,@b=b,@c=c from #abc where a=1
select @a,@b,@c

end

drop table #abc


is it that if the data returns more than one row the varibles hold the last value.....

thanks

======================================
Ask to your self before u ask someone

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2002-07-23 : 05:20:22
the "select @a,@b,@c" does nothing ..... it has no rows to select from....you also are NOT loading it with any information....


declare @a numeric
select @a=1
print @a

WILL return something....in this form it's a bit like a SET statement....but select @a has no meaning/effect...(what is it being SET to??)


If you put "PRINT" statements between each "select" statement ou would see what I mean.

Go to Top of Page

khalik
Constraint Violating Yak Guru

443 Posts

Posted - 2002-07-23 : 23:45:28

thanks AndrewMurphy did u try mu code..just paste the code and see what the result is... @a , @b , @c hold value... try it and then ....

======================================
Ask to your self before u ask someone
Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2002-07-26 : 09:14:02
Khalik....I did run your code....

but the output as seen in QA....shows nothing for the
"select @a,@b,@c" statements....which is EXACTLY what I was getting across.....and which is what I thought you wanted explained.....


if you put "print " statements in between ALL the "SELECT" statements you will see what lines of the output relate to which "SELECT"


....that's what I did....and that's why I was able to make the statement in my original post....

Go to Top of Page
   

- Advertisement -