Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 2895

Re: How to write lookup for this Sql Statements

$
0
0

they given another Sql statement for the Query and for two fields they want lookup otherwise it is giving time out error when included in the Sql statement.

 

The other Sql statement is

 

select a.cust_acct_no as Cust_acct,

casewhen b.assoc_acct_no isnullthen' ' 

      else b.assoc_acct_no endas Parent_cust_acct,

so_cd,

MKT_SEG_CD,

casewhen (select prnt_cust_name from proddb2.CACTPCH z where z.cust_acct_no = a.cust_acct_no) isnull

     then cust_name

     else (select prnt_cust_name from proddb2.CACTPCH z where z.cust_acct_no = a.cust_acct_no) endas Cust_Name,

ADDR_LN_1 as street,

city,

st_cd as state,

zip_cd as zip,

ctry_cd as country_cd,

' 'as ACCT_TYPE,

' 'as CUST_TYPE,

case when (select prnt_cust_name from proddb2.CACTPCH z where z.cust_acct_no = a.cust_acct_no) is null and substr(cust_name, 1, 6) = 'STOCK ' then 'S' 

     when (select substr(prnt_cust_name,1,6) from proddb2.CACTPCH z where z.cust_acct_no = a.cust_acct_no) = 'STOCK ' then 'S'

       else ' ' end as STOCK_INDC

 

 

from proddb2.svcacct_DPIMS a

 

innerjoin proddb2.svcaddr con a.cust_acct_no = c.cust_acct_no andc.addr_type_cd = 'A' 

leftjoin proddb2.svckas b on a.cust_acct_no = b.cust_acct_no

where (a.ACTIVE_CUST_DATE > '2015-01-01' ) groupby

  1. a.cust_acct_no,
  2. b.assoc_acct_no,

so_cd,

MKT_SEG_CD, 

ADDR_LN_1,

city,

st_cd,

zip_cd,

ctry_cd,

cust_name

 

 

use this to Update the other fields:(they want this to be from lookup table)

 

case when (select d.tbl_seg_key from proddb2.lkuptbl d where d.tbl_name = 'TOPNATND' and substr(tbl_seg_key, 5,10) = a.cust_acct_no FETCH FIRST 1 ROWS ONLY ) is not null then 'National'

     when (select d.tbl_seg_key from proddb2.lkuptbl d where d.tbl_name = 'TOPNATN' and substr(tbl_seg_key, 5,10) = a.cust_acct_no FETCH FIRST 1 ROWS ONLY ) is not null then 'National'

      else ' '  end as acct_type,

case when (select d.tbl_seg_key from proddb2.lkuptbl d where d.tbl_name = 'TOPNATND' and substr(tbl_seg_key, 5,10) = a.cust_acct_no FETCH FIRST 1 ROWS ONLY ) is not null then 'Direct'

     else 'Non-Direct' end as cust_type,


Viewing all articles
Browse latest Browse all 2895

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>