Question

I have a SQL Server 2000 database with a table named Voters. One column in the table (PrecinctCode of type varchar(10)) is supposed to have a 4 digit code similar to A111 or D109, but some rows have a value of '999'. The rows with value '999' have the correct number in a different column (FaultCode of type varchar(50)). I want to copy the values from FaultCode to PrecinctCode when PrecinctCode = 999.

I ran this query

UPDATE Voters
SET PrecinctCode = FaultCode
WHERE (PrecinctCode = '999')

A message appears saying "3031 rows affected" but the affected rows still show 999 in the PrecinctCode column. I connect to the DB with Windows Authentication under the administrator account, so I don't think its a security issue.

Has anyone had an update query that would not update rows?

EDIT

I tried this query to retrieve the schema, it gave me nothing useful though.

SELECT  *
FROM    INFORMATION_SCHEMA.TABLES
where   TABLE_NAME like '%Voters%'

Would just posting the table design work? if not can you tell me a query to run to retrieve the information you need? Thanks.

No correct solution

OTHER TIPS

Try doing a SELECT first so you are certain what you are asking for:

SELECT FaultCode, PrecinctCode FROM Voters WHERE PrecinctCode = '999';

N.B. that if length of FaultCode exceeds 10 chars your UPDATE will fail.

For grins please try this

UPDATE Voters
SET PrecinctCode = FaultCode
WHERE PrecinctCode = '999' and FaultCode <> '999'

Or try

UPDATE Voters
SET PrecinctCode = RTRIM (FaultCode)
WHERE PrecinctCode = '999' 

And

select *, len(FaultCode)
from Voters
WHERE PrecinctCode = '999' 
  and PrecinctCode <> FaultCode

Maybe you should try to commit after the update

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top