0

I have a problem with the sintax below where i tried to union two DEs where the Month is the Primary Key. All Data Extension in the case have the fiedls type like Text.

ERROR: Query failed during execution. Error: Conversion failed when converting the nvarchar value 'July' to data type int.

select
Count(*) as [Users],
[Month] as [Month]
FROM [DE_1]
GROUP BY [Month]
UNION
Select 
[Month] as [Month],
Send as [Sends_Totally]
from [DE_2]
2

Your union the fields have to be in the same order, Since users is a count(int) in the first query and Month is a nvarchar, it can't convert the value 'July' to an INT.

A union requires the same number of fields with the same field type in the same order

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

Updated

I don't think your use case should be done with a Union but a join

SELECT
Count(*) as [Users],
a.[Month],
b.[Sends_Totally]
FROM [DE_1] a
JOIN [DE_2] b on a.Month = b.Month
GROUP BY [Month]
| improve this answer | |
  • I have a problem with this, @EazyE. Violation of PRIMARY KEY constraint. Cannot insert duplicate key in object 'DE_3'. The duplicate key value is (July). – Joao Marano Jul 22 '19 at 20:18
  • @JoaoMarano can both select queries return the value of July? – EazyE Jul 22 '19 at 20:21
  • Yes, but the 'month' field is primary key'. I want the DE_2 just update the field Sends_Totally in one SQL. – Joao Marano Jul 22 '19 at 20:25
  • I think you shouldn't use a UNION but a JOIN, I've updated my answer – EazyE Jul 22 '19 at 20:29
  • So Thanks, @EazyE – Joao Marano Jul 23 '19 at 21:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.