Solved

MSSQL query failing inside job

Posted on 2014-09-26
3
127 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

In this article I will describe the Detach & Attach 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.
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.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now