Question Locked

Charindex in SQL Update Statement

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

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

2 replies

by tony hopkinson

SET [field1] = (substring([field2],(-2),(charindex('-',[field2]) + tbl.Displacement)))

updated no rows means your where clause is wrong not the set...

This discussion is closed to new replies.