Solved

Union query will not update table

Posted on 2014-10-02
3
83 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

729 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