Solved

How do I convert this SQL Statement from SQL Server?

Posted on 2008-10-09
3
2,316 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
tempdb latch contention 12 47
How to base a filter depending on fields contents? 15 47
Need to update TableA to TableB 6 33
MS SQL Pivot table help 4 12
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

912 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

24 Experts available now in Live!

Get 1:1 Help Now