can insert the derived table in Between clause?
Teradata Teradata Discussion Forums Teradata.com Discussion Forum
Visit Teradata.com
Home       Guidelines    Member List
Welcome Guest ( Login | Register )
        


This online forum is for user-to-user discussions of Teradata products, and is not an official customer support channel for Teradata. If you require direct assistance, please contact Teradata support.


can insert the derived table in Between... Expand / Collapse
Author
Message
Posted 2/8/2006 1:58:08 AM
Forum Member

Forum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum Member

Group: Forum Members
Last Login: Yesterday @ 1:11:10 AM
Posts: 34, Visits: 7
Hi All,
I needed to get the dates for report at run time, the dates should be in some range, hence the "between" clause can be used. but I am unable to give the select statement in the "between" clause. as explained the query below

select * from date_exmp where
req_dte between (select date-10) and date;

is not working, giving the following error:

Code = 3706.
3706: Syntax error: expected something between '(' and the 'select' keyword.
Output directed to Answer set window


FYI: the same query is running when i m giving the req_dte using mathematical operators as:-

where
req_dte >= (select date-10) and
req_dte <= date;

IF any one know the solution kindly reply as early as possible

Thanks


Manoj kp

Post #3495
Posted 2/8/2006 9:44:30 AM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: 7/24/2008 8:31:03 AM
Posts: 109, Visits: 22
The following query will work:

select * from date_exmp where
req_dte between date-10 and date;
Post #3504
Posted 2/9/2006 5:13:27 AM
Forum Member

Forum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum Member

Group: Forum Members
Last Login: Yesterday @ 1:11:10 AM
Posts: 34, Visits: 7
Hi TD_ARch,
Thanks for your reply, but my Actual requirement is that I wanted to put select statement in between clause, whether it is possible, please let me know, if not their is any specific reason for it?

please let me know



Manoj kp

Post #3514
Posted 2/9/2006 11:13:47 AM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: 10/7/2008 12:54:51 PM
Posts: 116, Visits: 20
Manoj,
I am not sure why it does not allow an select in the between clause, but it does not allow a select. The option that you had "where date_val >= (select .....) and date_val <= (select .....)" Infact this is what a between clause should resolve to. and the select query should retreive only one value or else you get a error : 3669 : More than one value was returned by a subquery.




Feroz Shaik
Post #3515
Posted 2/17/2006 3:27:20 PM
Junior Member

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member

Group: Forum Members
Last Login: 5/11/2006 7:20:00 PM
Posts: 24, Visits: 1
Why BETWEEN not working and comparison operator working is probably because of their syntax. Given below is thier syntax as given in Teradata manuals.

1. Syntax of BETWEEN is: -
expression1 BETWEEN expression2 AND expression 3
Here it does not expect subquery.

2. Syntax of comparison operator is: -
expression1 operator (subquery)
Here the subquery is allowed at the right side of the comparison operator. You can alter your query "where (select date-10) <= req_dte and req_dte <= date;" it will not work as the subquery should be on the right of the operator.

Hope this help. Anyway, you have already found the alternative to achive the final result.
Post #3545
Posted 2/20/2006 8:40:48 AM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: 6/9/2008 2:55:55 PM
Posts: 185, Visits: 2
You can code this as a derived table, rather than putting a subquery in the WHERE clause.

Try this:

select *
from date_exmp a
,(select max(date - 10) derived_dt
from some_table) b
where req_dte between derived_dt and date;

You can put your subquery in the derived table "b" above. Just be sure that your derived table returns only one row; otherwise you won't get the answer that you want.

Thanks,
Barry
Post #3548
« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 2 ( 2 guests, 0 members, 0 anonymous members )
No members currently viewing this topic.


All times are GMT -5:00, Time now is 9:42pm

Powered By InstantForum.NET v4.1.4 © 2008
Execution: 0.234. 10 queries. Compression Disabled.