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 |
Palermo
Starting Member
25 Posts |
Posted - 2013-10-16 : 17:48:01
|
I want to search or set, whichever way works, for a specific name in a field then change it to the value I have stored in a variable. If I wanted to search for the name 'Ric Flair' in a table and replace it with the variable Harely Race, how would I do that? Needless to say this doesn't work :DECLARE @newname nchar(20)SET @newname = 'Harely Race';FROM dbo.WrestlersWHERE Grappler = 'Ric Flair'; |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2013-10-16 : 17:54:23
|
UPDATE dbo.WrestlersSET Grappler = @newnameWHERE Grappler = 'Ric Flair'Tara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
Palermo
Starting Member
25 Posts |
Posted - 2013-10-16 : 17:56:30
|
Thanks but I know how to do it using the UPDATE command, I want to know how to do it using a variable. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2013-10-16 : 17:59:53
|
I'm confused. What I posted IS using a variable.Tara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2013-10-16 : 18:02:03
|
Let me be more clear as I only provided the UPDATE statement, assumed you knew you still need to declare/set the variable:DECLARE @newname nchar(20)SET @newname = 'Harely Race';UPDATE dbo.WrestlersSET Grappler = @newnameWHERE Grappler = 'Ric Flair'Tara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
Palermo
Starting Member
25 Posts |
Posted - 2013-10-16 : 18:05:34
|
Thanks that did it!Yes I appreciate it makes no sense whatsoever to use a variable instead of the UPDATE command by itself but it's for coursework and the notes state look up how to use a variable in Transact-SQL. |
|
|
|
|
|