Solved

MSSQL query failing inside job

Posted on 2014-09-26
3
132 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

730 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