Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2006-07-07
3
Medium Priority
?
717 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 1000 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 1000 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

722 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