Solved

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

Posted on 2006-07-07
3
703 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 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

828 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