cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
sagidam Frequent Visitor
Frequent Visitor

sql command "union"

I am trying to union two tables by this command on import data

 

"SELECT 'XXXX' AS SiteName, * FROM XXXX.dbo.jurnaltrans

union
SELECT 'YYYY' AS SiteName, * FROM YYYY.dbo.jurnaltrans"

 

and get this ERROR

"DataSource.Error: Microsoft SQL: Error converting data type varchar to float.
Details:
    DataSourceKind=SQL
    DataSourcePath=XXXXXXXXXX
    Message=Error converting data type varchar to float.
    Number=8114
    Class=16

PLEASE HELP

2 ACCEPTED SOLUTIONS

Accepted Solutions
JM_nxgn Regular Visitor
Regular Visitor

Re: sql command "union"

@sagidam 

I'm not sure this is the correct place to ask a question like this, but oh well.

 

Have you ensured that both tables have the same number of columns, and both the order of the columns are the same and the data type.

View solution in original post

Community Support Team
Community Support Team

Re: sql command "union"

Hi @sagidam ,

 

The UNION operator is used to combine the result-set of two or more SELECT statements.

  • Each SELECT statement within UNION must have the same number of columns
  • The columns must also have similar data types
  • The columns in each SELECT statement must also be in the same order

 

You may list the corresponding columns like syntax codes below:

 

SELECT City, Country FROM Customers

WHERE Country='Germany'

UNION

SELECT City, Country FROM Suppliers

WHERE Country='Germany'

ORDER BY City;

 

You may also create a calculated table like DAX below to combine columns using DAX .

 

New table= UNION (SELECTCOLUMNS(Table1,"Account Name",Table1[A]),SELECTCOLUMNS(Table2,"Account Name",Table2[B]))

For more professional SQL help, you may post your issue in SQL Server Community.

 

Best Regards,

Amy

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

View solution in original post

2 REPLIES 2
JM_nxgn Regular Visitor
Regular Visitor

Re: sql command "union"

@sagidam 

I'm not sure this is the correct place to ask a question like this, but oh well.

 

Have you ensured that both tables have the same number of columns, and both the order of the columns are the same and the data type.

View solution in original post

Community Support Team
Community Support Team

Re: sql command "union"

Hi @sagidam ,

 

The UNION operator is used to combine the result-set of two or more SELECT statements.

  • Each SELECT statement within UNION must have the same number of columns
  • The columns must also have similar data types
  • The columns in each SELECT statement must also be in the same order

 

You may list the corresponding columns like syntax codes below:

 

SELECT City, Country FROM Customers

WHERE Country='Germany'

UNION

SELECT City, Country FROM Suppliers

WHERE Country='Germany'

ORDER BY City;

 

You may also create a calculated table like DAX below to combine columns using DAX .

 

New table= UNION (SELECTCOLUMNS(Table1,"Account Name",Table1[A]),SELECTCOLUMNS(Table2,"Account Name",Table2[B]))

For more professional SQL help, you may post your issue in SQL Server Community.

 

Best Regards,

Amy

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

View solution in original post

Helpful resources

Announcements
Can You Solve These Challenge

Challenge: Can You Solve These?

Find out how to participate in the first Power BI 'Can You Solve These?' challenge.

New Badges

Incoming: New and Improved Badges

Exciting news: We've given our badges an overhaul and added brand news ones.

Ask Amir Anything

Exclusive LIVE Community Event No. 2 – Ask Amir Anything

Next in our Triple A series: Ask Amir Netz questions about the latest updates, features and future.

Analytics in Azure virtual event

Analytics in Azure virtual event

Experience a limitless analytics service built to ingest, prep, manage, and serve data for immediate use in Power BI.

Users Online
Currently online: 139 members 1,485 guests
Please welcome our newest community members: