Solved

How do I convert this SQL Statement from SQL Server?

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
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.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

856 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