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 |
|
bubberz
Constraint Violating Yak Guru
289 Posts |
Posted - 2005-08-29 : 13:50:41
|
| I have three tables to update, and want to be able to set a variable value in one spot rather than having to do it three places.Right now, let's say I have to update a title in three tables by Number. I'm doing the following, but want to know if I can set variable values in one spot, then use that in the query. So, the next time an update needs to happen, I just change the Title and the Number (two changes, rather than six changes).--Title variable here--Number variable hereUPDATE WInfoSET [Title] = 'Equipment'WHERE [Number] like '01'Go--Now do DictionaryGoUPDATE DictionarySET [Title] = 'Capital'WHERE [Number] like '01'Go--Now do WTableGoUPDATE WBS_TableSET [WBS Title] = 'Capital'WHERE [Number] like '01'Go |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-08-29 : 13:52:09
|
| Yes you can do that. That's what variables are for!Tara |
 |
|
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2005-08-29 : 16:04:01
|
| DECLARE @Title varchar(30), @Number varchar(5) --weird to have a number as varchar...SELECT @Title = 'Equipment', @Number = '01'UPDATE WInfoSET [Title] = @TitleWHERE [Number] like @Number--Lumbago"Real programmers don't document, if it was hard to write it should be hard to understand" |
 |
|
|
bubberz
Constraint Violating Yak Guru
289 Posts |
Posted - 2005-08-29 : 16:34:16
|
| Thanks Lumbago!That's exactly what I finally got to work! |
 |
|
|
|
|
|