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
 General SQL Server Forums
 New to SQL Server Programming
 Update Table

Author  Topic 

vedjha
Posting Yak Master

228 Posts

Posted - 2010-01-29 : 07:56:44
Hello, I have to update first Character of string in column1

I have Write query as:

update table set substring(column1,1,1)='W'
where substring(column1,1,1)='X'

it gives an exception as :

Incorrect Syntax near ','

http://kiransoftech.com

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2010-01-29 : 08:09:17
substring only returns the value, not a reference that you can modify. What you are trying to do can be done in other ways, for example:
update tablename set column1 = stuff(column1,1,1,'W') where left(column1,1) = 'X'
Go to Top of Page

vedjha
Posting Yak Master

228 Posts

Posted - 2010-01-29 : 08:15:31
Thank You .
:)

http://kiransoftech.com
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-30 : 00:33:29
[code]update tablename set column1 = stuff(column1,1,1,'W') where column1 like 'X%'[/code]

if you need to use existing index on column1
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-01-30 : 03:00:41
"if you need to use existing index on column1"

Better method anyway IMHO. Takes advantage of any future index too and, I think, is a better "habit"
Go to Top of Page
   

- Advertisement -