Solved

Union query will not update table

Posted on 2014-10-02
3
82 Views
Last Modified: 2014-10-02
I have the following union query that runs on its own and retrieves 7500 records:
SELECT     *
FROM         dbo.vw_EmpBaseRt_Pos_Change
UNION
SELECT     *
FROM         dbo.vw_EmpDirDep_Change
UNION
SELECT     *
FROM         dbo.vw_EmpPTO_Change
UNION
SELECT     *
FROM         dbo.vw_EmpStatus_Change
UNION
SELECT     *
FROM         dbo.vw_EmpTax_Change
UNION
SELECT     *

Open in new window


When I create a new query to insert the results of this union query into a table:

insert into livedb.dbo.tbl_Union
 
select  FLD12,FLD13,FLD14,FLD15,FLD16,FLD17,FLD18,FLD19,
FLD20,FLD21,FLD22,FLD23,FLD24,FLD25,FLD26,FLD27,FLD28,FLD29,
FLD30,FLD31,FLD32,FLD33,FLD34,FLD35,FLD36,FLD37,FLD38,FLD39,
FLD40,FLDA,FLDB,FLDC,FLDD,FLDE,FLDF,FLDG,FLDH,FLDI

from
(

SELECT     *
FROM         dbo.vw_EmpBaseRt_Pos_Change
UNION
SELECT     *
FROM         dbo.vw_EmpDirDep_Change
UNION
SELECT     *
FROM         dbo.vw_EmpPTO_Change
UNION
SELECT     *
FROM         dbo.vw_EmpStatus_Change
UNION
SELECT     *
FROM         dbo.vw_EmpTax_Change
UNION
SELECT     *
FROM         dbo.vw_EmpWH_Change
) a

Open in new window


I get an error:

Msg 8152, Level 16, State 14, Line 1
String or binary data would be truncated.
The statement has been terminated.


I have determined that the error is being caused by the first Select:

SELECT     *
FROM         dbo.vw_EmpBaseRt_Pos_Change
UNION


All the columns exist in each of the 6 views, in the same order and have be formatted the same.

I appeciate any help on this matter.

Thanks

glen
0
Comment
Question by:GPSPOW
[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
3 Comments
 
LVL 18

Expert Comment

by:Dave Ford
ID: 40357492
Based on the error message, it appears that at least one of the columns in livedb.dbo.tbl_Union is too narrow to hold the data being inserted. What are the field-lengths involved?

HTH,
DaveSlash
0
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 500 total points
ID: 40357493
You've got a column(s) in table:

 livedb.dbo.tbl_Union

that are not long enough to hold the data coming in.  You either have to lengthen the columns or shorten the data.
0
 

Author Closing Comment

by:GPSPOW
ID: 40357498
Thanks

That did it.

Glen
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Dynamically Construct and Execute a SQL Server Statements 10 50
SQL Procedure 7 47
SQLCMD question to have fields created as fixed length 2 34
VM SQL server license. 1 57
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

739 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