Solved

Union query will not update table

Posted on 2014-10-02
3
73 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
3 Comments
 
LVL 18

Expert Comment

by:daveslash
Comment Utility
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:
ScottPletcher earned 500 total points
Comment Utility
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
Comment Utility
Thanks

That did it.

Glen
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

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