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 |
|
chris_wood99
Yak Posting Veteran
70 Posts |
Posted - 2011-07-06 : 08:52:15
|
| Hi All,I'm trying something fairly simple, think I need to insert a cursor as the query is complaining my subquery is returning more than one result.works fine as a select statement but when i try to convert to an update its not working as obviously returning the result set.UPDATE casinohostname_bakset hostname = (select SUBSTRING(hostname,1,3)+'1'+SUBSTRING(hostname,4,50) from casinohostname_bakwhere hostname like 'sit%') |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-07-06 : 08:59:18
|
| UPDATE casinohostname_bakset hostname = stuff(hostname,4,0,'1')where hostname like 'sit%'JimEveryday I learn something that somebody else already knew |
 |
|
|
chris_wood99
Yak Posting Veteran
70 Posts |
Posted - 2011-07-06 : 09:10:44
|
| sweet, what version did stuff come in ? |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2011-07-06 : 09:17:40
|
| Since at least SQL Server 6.5. |
 |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-07-06 : 09:25:59
|
| You don't need stuff - it's just that your update syntax was wrongThis would also workUPDATE casinohostname_bakset hostname = SUBSTRING(hostname,1,3)+'1'+SUBSTRING(hostname,4,50) where hostname like 'sit%'==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|
|
|