Solved

MSSQL query failing inside job

Posted on 2014-09-26
3
129 Views
Last Modified: 2014-09-29
Hi,

This is a little odd to me.  I have an update query that I'm running in SSMS that works fine.  But inside a job it fails.

String or binary data would be truncated. [SQLSTATE 22001] (Error 8152)  The statement has been terminated. [SQLSTATE 01000] (Error 3621).  The step failed.

UPDATE einfo
SET emailAddress = ad.mail
FROM einfo e, ourdba.dbo.ourvw_adusers2 ad
WHERE ltrim(rtrim(e.id)) = ad.employeeid
AND ltrim(rtrim(e.emailaddress)) <> ad.mail
AND empStatus in ('A', 'L')



Basically it is taking the data in a view, created by pulling the data from active directory and creating the view.  I have created the view using the following select:
SELECT cn, sAMAccountName, convert(varchar(50), mail) as mail, l, userPrincipalName, distinguishedname, convert(varchar(10),employeeid) as employeeid
The table being updated einfo has emailaddress VARCHAR(50) and employeeid VARCHAR(10).  

Why is this failing during the job?  The source VIEW and destination table EINFO should have the same size data?

Getting a little crazy with this.

Thanks.
0
Comment
Question by:mcioffi209
  • 2
3 Comments
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 500 total points
ID: 40346876
emailAddress = ad.mail

what's ad.Mail's varchar size vs emailaddress varchar size?

to get around this you could do:

 emailAddress = cast(ad.mail as varchar(100))

or whatever, but you'll truncate the mail.  Try upgrading the size of emailaddress.

another simple query:

select max(len(mail)) adSize
from
ourdba.dbo.ourvw_adusers2
0
 

Author Comment

by:mcioffi209
ID: 40350398
Thanks for the response.

Well the big part of the problem is the triggers on the table.  We were rushing on a Friday and I missed the triggers.

But just to be complete.

emailaddress and admail are the exact same size in each source.  I created the view that ad.mail is from using a convert from the source.

Thanks again.
0
 

Author Closing Comment

by:mcioffi209
ID: 40350399
using the select helped me be sure that we had the proper column values.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

776 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