Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Union query will not update table

Posted on 2014-10-02
3
Medium Priority
?
102 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: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 70

Accepted Solution

by:
Scott Pletcher earned 2000 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how the fundamental information of how to create a table.

877 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