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.
| 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_idselect &@staff from staff_tbInstead 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_tborselect staff_id from staff_tbthe first one assigns the value to a variable which you can use later for other purposethe second one retrieves the value, more like showing it or if used with if exists, may tell you if there are rows in staff_tbreally depends on what you want to do--------------------keeping it simple... |
 |
|
|
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 dodeclare @staff char(10)set @staff = 'staff_tb.staff_id'EXEC('select '+@staff+' from staff_tb')MadhivananFailing to plan is Planning to fail |
 |
|
|
daquoc
Starting Member
35 Posts |
Posted - 2006-03-07 : 19:53:51
|
| Thank you.daquoc |
 |
|
|
|
|
|