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)
 2 different queries have same result ?

Author  Topic 

daquoc
Starting Member

35 Posts

Posted - 2006-03-06 : 22:05:23
Hi all,

Can I use

declare @staff char(10)
set @staff = staff_tb.staff_id
select &@staff from staff_tb

Instead of using

"select staff_tb.staff_id from staff_tb"

Thanks. Nice working day.
daquoc


jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2006-03-06 : 22:19:16
you can:

declare @staff char(10)
select @staff=staff_id from staff_tb
or
select staff_id from staff_tb

the first one assigns the value to a variable which you can use later for other purpose

the second one retrieves the value, more like showing it or if used with if exists, may tell you if there are rows in staff_tb

really depends on what you want to do

--------------------
keeping it simple...
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-03-07 : 01:25:39
You should use Dynamic SQL, to do what you are trying to do

declare @staff char(10)
set @staff = 'staff_tb.staff_id'
EXEC('select '+@staff+' from staff_tb')


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

daquoc
Starting Member

35 Posts

Posted - 2006-03-07 : 19:53:51
Thank you.
daquoc
Go to Top of Page
   

- Advertisement -