Solved

MSSQL query failing inside job

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

Accepted Solution

by:
Kyle Abrahams earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
using the select helped me be sure that we had the proper column values.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
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 …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 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

11 Experts available now in Live!

Get 1:1 Help Now