Charindex in SQL Update Statement - TechRepublic
Question
February 10, 2010 at 04:36 AM
martinbullock15

Charindex in SQL Update Statement

by martinbullock15 . Updated 16 years, 4 months ago

Hi

How can i put this in to a SQL Update statement:

(substring([STKNAME2],(-2),(charindex(‘-‘,[STKNAME2]) + 5)))

I have tried this but it updated no rows:

UPDATE [tbl]
SET [field1] = (substring([field2],(-2),(charindex(‘-‘,[field2]) + 5)))
WHERE [field3] = [value] AND
[field4] = [value]

I have put the substring statement directly into the SQL table design as a computed column (which worked) but i need to be able to change the final value (+5) depending on the WHERE clause.

Thanks in advance for any help

Martin

This discussion is locked

All Comments