Thursday, March 22, 2012

Error 8152

Hi,
I have the following problem. I create a small request to truncate a column
(see below). When I run it, I get an error 8152. I don't understand why.
I have no null value into the table.
I would appreciate any help
tia
Samuel
ALTER TABLE [dbo].[ArticleNumber] ALTER COLUMN [Number] [varchar] (35)
COLLATE Latin1_General_CI_AS NOT NULLError 8152 ("String or binary data would be truncated.") indicates that you
have data in the column that is longer than the length you are trying to set
it to, i.e. longer than 35 characters.
Do
SELECT MAX(LEN(Number)) FROM ArticleNumber
to find out how long the values in that column are.
Jacco Schalkwijk
SQL Server MVP
"Samuel Bernard" <SamuelBernard@.discussions.microsoft.com> wrote in message
news:0F9B9A47-B83C-43B0-A6C1-F6D4EE61C56E@.microsoft.com...
> Hi,
> I have the following problem. I create a small request to truncate a
> column
> (see below). When I run it, I get an error 8152. I don't understand why.
> I have no null value into the table.
> I would appreciate any help
> tia
> Samuel
> ALTER TABLE [dbo].[ArticleNumber] ALTER COLUMN [Number] [varchar] (35)
> COLLATE Latin1_General_CI_AS NOT NULL|||Hi
What data type is the column now?
The error message indicates that there is data, with lergth exceeding 35, in
the column and SQL Server will not just throw the extra data away.
Run something like this frist to remove the extra characters (NOTE: You
loose data by doing this, so only run it after careful consideration and
testing)
Update ArticleNumber
SET Number = SUBSTRING(Number, 1, 35)
Regards
--
--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"Samuel Bernard" wrote:

> Hi,
> I have the following problem. I create a small request to truncate a colum
n
> (see below). When I run it, I get an error 8152. I don't understand why.
> I have no null value into the table.
> I would appreciate any help
> tia
> Samuel
> ALTER TABLE [dbo].[ArticleNumber] ALTER COLUMN [Number] [varchar] (35)
> COLLATE Latin1_General_CI_AS NOT NULL|||Hi Jacco,
Thanks you for your quick and GOOD answer.
"Jacco Schalkwijk" wrote:

> Error 8152 ("String or binary data would be truncated.") indicates that yo
u
> have data in the column that is longer than the length you are trying to s
et
> it to, i.e. longer than 35 characters.
> Do
> SELECT MAX(LEN(Number)) FROM ArticleNumber
> to find out how long the values in that column are.
>
> --
> Jacco Schalkwijk
> SQL Server MVP
>
> "Samuel Bernard" <SamuelBernard@.discussions.microsoft.com> wrote in messag
e
> news:0F9B9A47-B83C-43B0-A6C1-F6D4EE61C56E@.microsoft.com...
>
>

No comments:

Post a Comment