Solved

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

Posted on 2006-07-07
3
695 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
3 Comments
 
LVL 142

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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now