Solved

Union query will not update table

Posted on 2014-10-02
3
80 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
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 Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Download ms sql express. 2 25
SQL Log size 3 17
SQL Quer 4 21
SQL Availablity Groups List 2 7
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
I have a large data set and a SSIS package. How can I load this file in multi threading?
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.
Viewers will learn how the fundamental information of how to create a table.

840 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