Solved

MSSQL query failing inside job

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

707 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