Solved

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

Posted on 2006-07-07
3
711 Views
Last Modified: 2012-05-05
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?
0
Comment
Question by:fylix0000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 250 total points
ID: 17062185
your statement should do that already, but possibly puts a warning...
run this then before:
UPDATE memorizedaddress SET city = LEFT(city, 24)
0
 
LVL 25

Accepted Solution

by:
dstanley9 earned 250 total points
ID: 17062191
try

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

ALTER TABLE memorizedaddress ALTER COLUMN city VARCHAR(24)
0
 

Author Comment

by:fylix0000
ID: 17062208
Thanks, so basically I truncate all the data first before doing the altering....thanks.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question