updating part of a field in SQL Server 2000

  • I am trying to update part of a char(50) field, and am having a lot of difficulty with the syntax. I'm trying to update positions 37, 4 and 41, 4 with zeros if a certain condition is met in a different field in the table. I've been trying to set the field as follows:

    SET SUBSTRING(ADDITIONALDATA,37,4) = '0000' but it seems to have a problem near the '('.

    Thanks

  • That syntax works only in VB.  You need to do something like this :

    UPDATE dbo.Table set ColName = LEFT(ColName, 36) + '0000' + RIGHT(ColName, 14) where...

  • THANK you very much! That seems to have worked.

  • The STUFF function might also help.

    UPDATE table

    SET AdditionalData = STUFF(AdditionalData,37,4, '0000')

    WHERE certaincondition = 1

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply