SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SQL Agent Job Error - String or binary data would be truncated. [SQLSTATE 22001] (Error 8152)


SQL Agent Job Error - String or binary data would be truncated. [SQLSTATE 22001] (Error 8152)

Author
Message
joshdbguy
joshdbguy
SSChasing Mays
SSChasing Mays (627 reputation)SSChasing Mays (627 reputation)SSChasing Mays (627 reputation)SSChasing Mays (627 reputation)SSChasing Mays (627 reputation)SSChasing Mays (627 reputation)SSChasing Mays (627 reputation)SSChasing Mays (627 reputation)

Group: General Forum Members
Points: 627 Visits: 725
I'm running into the following message, "String or binary data would be truncated. [SQLSTATE 22001] (Error 8152)" when running a sql agent job. I'm attempting to execute a stored procedure through the job. Keep in mind that when I run the stored procedure in a normal query window, it works fine and only fails when running it as a scheduled job. My guess is that it has to do with how SQL Jobs execute procedures (especially long procedures) but I have no idea how to fix this. If I use Set Ansi_Warnings OFF, the job will work fine, however, I don't know what other issues this may cause.

Thanks for the help.
TacticalDragon
TacticalDragon
Grasshopper
Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)

Group: General Forum Members
Points: 13 Visits: 61
Hey Josh,

From what i've read after doing some searches is, we would need to know what code is running. Alot of people that have had the same issue had formatting issues.

Cheers,

Tac
joshdbguy
joshdbguy
SSChasing Mays
SSChasing Mays (627 reputation)SSChasing Mays (627 reputation)SSChasing Mays (627 reputation)SSChasing Mays (627 reputation)SSChasing Mays (627 reputation)SSChasing Mays (627 reputation)SSChasing Mays (627 reputation)SSChasing Mays (627 reputation)

Group: General Forum Members
Points: 627 Visits: 725
I was able to grab the specific code that's causing the problem, here you go,

USE [ARCHIVE]
GO
/****** Object: StoredProcedure [dbo].[SP_Archive_Cleanup] Script Date: 09/20/2013 22:54:57 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[SP_Archive_Cleanup] @TABLE VARCHAR(10)

AS
BEGIN

IF (@TABLE='ALL')
BEGIN


DELETE
FROM PRODUCTION.dbo.TABLE1
WHERE PK IN (SELECT PK FROM ARCHIVE.dbo.TABLE1)


DELETE
FROM PRODUCTION.dbo.TABLE2
WHERE PK IN (SELECT PK FROM ARCHIVE.dbo.TABLE2)

DELETE
FROM PRODUCTION.dbo.TABLE3
WHERE PK IN (SELECT PK FROM ARCHIVE.dbo.TABLE3)


DELETE
FROM PRODUCTION.dbo.TABLE4
WHERE PK IN (SELECT PK FROM ARCHIVE.dbo.TABLE4)


DELETE
FROM PRODUCTION.dbo.TABLE5
WHERE PK IN (SELECT PK FROM ARCHIVE.dbo.TABLE5)


DELETE
FROM PRODUCTION.dbo.TABLE6
WHERE PK IN (SELECT PK FROM ARCHIVE.dbo.TABLE6)

END

IF (@TABLE = 'TABLE1')
BEGIN


DELETE
FROM PRODUCTION.dbo.TABLE1
WHERE PK IN (SELECT PK FROM ARCHIVE.dbo.TABLE1)

END

IF (@TABLE = 'TABLE2')
BEGIN


DELETE
FROM PRODUCTION.dbo.TABLE2
WHERE PK IN (SELECT PK FROM ARCHIVE.dbo.TABLE2)

END

IF (@TABLE = 'TABLE3')
BEGIN


DELETE
FROM PRODUCTION.dbo.TABLE3
WHERE PK IN (SELECT PK FROM ARCHIVE.dbo.TABLE3)

END

IF (@TABLE ='TABLE4')
BEGIN


DELETE
FROM PRODUCTION.dbo.TABLE4
WHERE PK IN (SELECT PK FROM ARCHIVE.dbo.TABLE4)

END

IF (@TABLE = 'TABLE5')
BEGIN


DELETE
FROM PRODUCTION.dbo.TABLE5
WHERE PK IN (SELECT PK FROM ARCHIVE.dbo.TABLE5)

END

IF (@TABLE = 'TABLE6')
BEGIN


DELETE
FROM PRODUCTION.dbo.TABLE6
WHERE PK IN (SELECT PK FROM ARCHIVE.dbo.TABLE6)

END

END
TacticalDragon
TacticalDragon
Grasshopper
Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)

Group: General Forum Members
Points: 13 Visits: 61
Hello Josh,

The other posts that i've seen the actual variable was just too small to hold the information at some point. What i would do is try increasing the VARCHAR(10) to something like VARCHAR(20) and see if the code runs Smile

you may have to play around with that size to see what works.

Please let me know if that works out for you.

Cheers,

Tac
kapil_kk
kapil_kk
Hall of Fame
Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)

Group: General Forum Members
Points: 3079 Visits: 2766
may be the value you are passing to the variable @table is greater than varchar(10) which results in string truncation..
please check this

_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
SrcName
SrcName
SSC-Enthusiastic
SSC-Enthusiastic (174 reputation)SSC-Enthusiastic (174 reputation)SSC-Enthusiastic (174 reputation)SSC-Enthusiastic (174 reputation)SSC-Enthusiastic (174 reputation)SSC-Enthusiastic (174 reputation)SSC-Enthusiastic (174 reputation)SSC-Enthusiastic (174 reputation)

Group: General Forum Members
Points: 174 Visits: 394
use sp_help TABLENAME from production and archive, and checked if data type are same in both table.
in this case our interest is PK column
joshdbguy
joshdbguy
SSChasing Mays
SSChasing Mays (627 reputation)SSChasing Mays (627 reputation)SSChasing Mays (627 reputation)SSChasing Mays (627 reputation)SSChasing Mays (627 reputation)SSChasing Mays (627 reputation)SSChasing Mays (627 reputation)SSChasing Mays (627 reputation)

Group: General Forum Members
Points: 627 Visits: 725
Unfortunately, it's none of those issues. However, I did notice something new.

I removed the stored procedure from my original large procedure as it's not necessarily needed, but it does fix some potential issues that could arise. I just wanted to see what happened if I did that. When I execute the job now, it says it completed, however, even though no errors are displayed the script didn't work. When I run the same exact procedure and script manually, it works fine. I've been looking around on some forums and it seems like there are quite a few people who have similar issues running large scripts and procedures via sql agent jobs. I'm going to try to run the script via a bat file to see how it works. If it works fine, then I'm going to write sql agent jobs off as just being finicky.

Perhaps one of you may know if there's a good writeup behind sql jobs somewhere that explains exactly how it works. That could help me understand why this job keeps failing.

Thanks,

Josh
vdanko 99274
vdanko 99274
Grasshopper
Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)

Group: General Forum Members
Points: 10 Visits: 6
I realize this is an old post - but perhaps others - like me find this entry due to a similar problem. In my case I had an insert statement with a select statement to load a reporting table. The solution turned out to be that I had a field name that had a space in it and I had used double quotes around the field (not smart) Once I changed it to [] around the field name the problem went away.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search