Solved

How do I convert this SQL Statement from SQL Server?

Posted on 2008-10-09
3
2,295 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
  • 2
3 Comments
 
LVL 7

Expert Comment

by:Cedric_D
Comment Utility
try replace two UNION parts...
0
 

Accepted Solution

by:
SpeedsterZ28 earned 0 total points
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
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.
Viewers will learn how the fundamental information of how to create a table.

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now