How to alter column and truncate the data of that column?

ALTER TABLE memorizedaddress ALTER COLUMN city VARCHAR(24)

Hi, above is the statment I tried to alter my column length to 24.   However in my database the original size is 25, there is one entry that populate all 25 characters.  Is there a way to alter this column length so it will cut off the City entry that has 25 characters into 24 characters?
fylix0000Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
dstanley9Connect With a Mentor Commented:
try

UPDATE memorizedaddress SET city = SUBSTRING(city,0,24)
WHERE LEN(city) > 24

ALTER TABLE memorizedaddress ALTER COLUMN city VARCHAR(24)
0
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
your statement should do that already, but possibly puts a warning...
run this then before:
UPDATE memorizedaddress SET city = LEFT(city, 24)
0
 
fylix0000Author Commented:
Thanks, so basically I truncate all the data first before doing the altering....thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.