Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Tue, 31 Aug 2004 @ 17:42:31 GMT


     
  <Prev Next>   <<First <Prev Next> Last>>  


Subj:   Re: Subquery in where condition
 
From:   Coffing Christopher L

Ya Know...

Whenever I have a tough SQL question, I call my good buddy Mike Larkins. But let me take a swag at this one.

It would be helpful to understand what you are trying to do with this statement. Please add some detail to what the need is and perhaps we can provide you with a solution.

You have a nested CASE statement that is trying to run a nested subquery in your original SELECT clause. I do not believe you can run a subquery before the FROM clause.

Subqueries are run in the FROM or WHERE clause of a SQL statement.

Perhaps you could take the subquery and turn it into a DERIVED Table and then capture the data that you are looking to return in your CASE statement.

      -----Original Message-----
     Select  a.pol_key
           ,a.cust_key
           ,
                     Case
                             When    a.ctl_St_cd = 'KY' THEN
            (
                     CASE
                             WHEN    b.cv_DESC IN ('BIPD', 'BI', 'APIP') THEN
     DT.cv_opt
                             ELSE    '  '  END)
                             ELSE
                  '  '
                     END
     FROM    D3141APM.POL_VH_CV_FCT A
          ,D3141APM.CV_DIM B, (
     Select  DISTINCT d.cv_opt
     From    D3141APM.POL_VH_CV_FCT A
                , d3141apm.pol_vh_cv_fct c
                       ,d3141apm.cv_dim d
     Where   c.pol_key = a.pol_key
             And       c.cust_key = a.cust_key
             And       c.cv_key = a.cv_key
             And       d.cv_key = a.cv_key
             And       d.cv_desc= 'PIP') DT
     WHERE
           A.CV_KEY = B.CV_KEY
             AND     A.CTL_ST_CD = 'KY'
     (additional criteria to join DT to A and/or B)

Some food for thought


Best Regards

Chris Coffing
AFKS O&M Lead Teradata DBA
Certified Teradata Master



     
  <Prev Next>   <<First <Prev Next> Last>>  
 
 
 
 
 
 
 
 
  
  Top Home Privacy Feedback  
 
 
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 15 Jun 2023