?
Solved

How do I convert this SQL Statement from SQL Server?

Posted on 2008-10-09
3
Medium Priority
?
2,420 Views
Last Modified: 2012-06-21
I am trying to convert the follow block of SQL from SQL Server to Teradata.

When compiling the code in Teradata, I get the following error:
3654:  Corresponding select-list expressions are incompatible.

How can I edit this code in order for it to compile properly?  Thank you!
select	EXTRACT(year from sold_date) ,
	EXTRACT(month from sold_date) ,
	EXTRACT(year from sold_date)*100+EXTRACT(month from sold_date), 
	ca.loan_num,
	sold_date,
	NULL,
	NULL
from	cmrmkt cr,
	cmacct ca
where	sold_date >= '2007-08-01' 
and	cr.receivable_id = ca.receivable_id
and	ca.loan_num not in (select loan_num from lcnam)
UNION
select	EXTRACT(year from sold_date) ,
	EXTRACT(month from sold_date) ,
	EXTRACT(year from sold_date)*100+EXTRACT(month from sold_date), 
	ca.loan_num,
	sold_date,
	lcm.charge_off_date,
	lcm.charge_off_flag
from 	cmrmkt cr,
	cmacct ca,
	lcnam lcm
where 	sold_date >= '2007-08-01'
and 	cr.receivable_id = ca.receivable_id
and 	ca.loan_num = lcm.loan_num;

Open in new window

0
Comment
Question by:SpeedsterZ28
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 7

Expert Comment

by:Cedric_D
ID: 22682422
try replace two UNION parts...
0
 

Accepted Solution

by:
SpeedsterZ28 earned 0 total points
ID: 22682539
Do you mean get rid of the UNION and just do two INSERT INTO statements for each SELECT statement?
0
 
LVL 7

Expert Comment

by:Cedric_D
ID: 22755149
I mean, try switch these two parts each other, to allow server to know type of last two columns.

To solve this definitely, make explicit cast for all columns of both unions, to desired datatypes.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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 ?
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Suggested Courses

741 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