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 2008 Forums
 Transact-SQL (2008)
 need cursor ?

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_bak
set
hostname = (select SUBSTRING(hostname,1,3)+'1'+SUBSTRING(hostname,4,50)
from casinohostname_bak
where hostname like 'sit%')

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-07-06 : 08:59:18
UPDATE casinohostname_bak
set
hostname = stuff(hostname,4,0,'1')
where hostname like 'sit%'

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

chris_wood99
Yak Posting Veteran

70 Posts

Posted - 2011-07-06 : 09:10:44
sweet, what version did stuff come in ?
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-07-06 : 09:17:40
Since at least SQL Server 6.5.
Go to Top of Page

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 wrong
This would also work

UPDATE casinohostname_bak
set 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.
Go to Top of Page
   

- Advertisement -