Solved

How do I convert this SQL Statement from SQL Server?

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
hyperlink data type in SQL 3 27
SQL Server - Set Value of Multiple Fields in One Query 10 24
TSQL - How to declare table name 26 30
SQL View nearest date 5 36
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

773 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