Jump to content

sql thathalu mamlu ravali


nenu_devudni

Recommended Posts

ee with clause lo una query lo highlight chesina col's add chesa ... and where clause lo add chesina new table vala records join vala thakuva ostunay ..  joins try chesina work avatledu .. deni ela fix cheyalo teliste cheppandi vaya @~`

 

WITH cte AS
     (SELECT   ucbcust_cust_code cust_code, 
           REPLACE(ucbcust_last_name,'|','') last_name,
           REPLACE(ucbcust_status_ind,'|','') status_ind,
           ucbcust_start_date start_date,
           ucbcust_activity_date activity_date,
           REPLACE(ucbcust_first_name,'|','') first_name, 
           REPLACE(ucbcust_middle_name,'|','') middle_name,
           REPLACE(ucbcust_toto_ind,'|','') toto_ind,
           REPLACE(ucbcust_builder_type,'|','') builder_type,
           REPLACE(ucbcust_pay_by_check_ind,'|','') check_ind,
           ucbcust_end_date end_date,
           REPLACE(ucbcust_email_address,'|','') email_addr,
           REPLACE(ucbcust_primary_prem_code,'|','') pr_prem_code,
           UPPER (ucrtele_phone_area) tele_area, 
           UPPER (ucrtele_phone_number) tele_num,
           UPPER (ucrtele_phone_ext) tele_ext, 
           UPPER (ucrtele_tele_code) tele_code,
           UCRADDR_STREET_NUMBER, 
           UCRADDR_PDIR_CODE_PRE, 
           UCRADDR_STREET_NAME, 
           UCRADDR_SSFX_CODE, 
           UCRADDR_PDIR_CODE_POST, 
           UCRADDR_UTYP_CODE, 
           UCRADDR_UNIT, 
           UCRADDR_CITY, 
           UCRADDR_STAT_CODE, 
           UCRADDR_ZIP, 
           UCRADDR_SEQNO,

               ROW_NUMBER () OVER (PARTITION BY ucbcust_cust_code ORDER BY ucrtele_tele_code) as rnum
          FROM ucbcust, ucrtele, ucraddr a
         WHERE ucbcust_cust_code = ucrtele_cust_code(+)
           AND ucbcust_cust_code(+) = ucraddr_cust_code
           AND a.UCRADDR_SEQNO = (SELECT MIN(b.ucraddr_seqno) 
                                                           FROM ucraddr b 
                                   WHERE b.ucraddr_cust_code = ucbcust_cust_code 
                                     AND b.ucraddr_atyp_code = 'MA'
                                     AND b.ucraddr_status_ind = 'A')

      ORDER BY DECODE (ucrtele_tele_code, 'BU', 'AA', 'HM', 'AB', 'ZZ'))
    SELECT *
     FROM cte
    WHERE rnum = 1

Link to comment
Share on other sites

  • Replies 32
  • Created
  • Last Reply

Top Posters In This Topic

  • nenu_devudni

    14

  • Bhai

    5

  • comradee

    4

  • 4Vikram

    3

Top Posters In This Topic

1 minute ago, JollyBoy said:

(+) idendi never seen before

outer join vuncle ... implicit joins antaru vetni .. left right outer ani rase badulu ela use cheyochu 

Link to comment
Share on other sites

1 hour ago, nenu_devudni said:

ee with clause lo una query lo highlight chesina col's add chesa ... and where clause lo add chesina new table vala records join vala thakuva ostunay ..  joins try chesina work avatledu .. deni ela fix cheyalo teliste cheppandi vaya @~`

 

WITH cte AS
     (SELECT   ucbcust_cust_code cust_code, 
           REPLACE(ucbcust_last_name,'|','') last_name,
           REPLACE(ucbcust_status_ind,'|','') status_ind,
           ucbcust_start_date start_date,
           ucbcust_activity_date activity_date,
           REPLACE(ucbcust_first_name,'|','') first_name, 
           REPLACE(ucbcust_middle_name,'|','') middle_name,
           REPLACE(ucbcust_toto_ind,'|','') toto_ind,
           REPLACE(ucbcust_builder_type,'|','') builder_type,
           REPLACE(ucbcust_pay_by_check_ind,'|','') check_ind,
           ucbcust_end_date end_date,
           REPLACE(ucbcust_email_address,'|','') email_addr,
           REPLACE(ucbcust_primary_prem_code,'|','') pr_prem_code,
           UPPER (ucrtele_phone_area) tele_area, 
           UPPER (ucrtele_phone_number) tele_num,
           UPPER (ucrtele_phone_ext) tele_ext, 
           UPPER (ucrtele_tele_code) tele_code,
           UCRADDR_STREET_NUMBER, 
           UCRADDR_PDIR_CODE_PRE, 
           UCRADDR_STREET_NAME, 
           UCRADDR_SSFX_CODE, 
           UCRADDR_PDIR_CODE_POST, 
           UCRADDR_UTYP_CODE, 
           UCRADDR_UNIT, 
           UCRADDR_CITY, 
           UCRADDR_STAT_CODE, 
           UCRADDR_ZIP, 
           UCRADDR_SEQNO,

               ROW_NUMBER () OVER (PARTITION BY ucbcust_cust_code ORDER BY ucrtele_tele_code) as rnum
          FROM ucbcust, ucrtele, ucraddr a
         WHERE ucbcust_cust_code = ucrtele_cust_code(+)
           AND ucbcust_cust_code(+) = ucraddr_cust_code
           AND a.UCRADDR_SEQNO = (SELECT MIN(b.ucraddr_seqno) 
                                                           FROM ucraddr b 
                                   WHERE b.ucraddr_cust_code = ucbcust_cust_code 
                                     AND b.ucraddr_atyp_code = 'MA'
                                     AND b.ucraddr_status_ind = 'A')

      ORDER BY DECODE (ucrtele_tele_code, 'BU', 'AA', 'HM', 'AB', 'ZZ'))
    SELECT *
     FROM cte
    WHERE rnum = 1

18

 

May be below condition valla vasthundi emo issue:    
   AND a.UCRADDR_SEQNO = (SELECT MIN(b.ucraddr_seqno) 
                                                           FROM ucraddr b 
                                   WHERE b.ucraddr_cust_code = ucbcust_cust_code 
                                     AND b.ucraddr_atyp_code = 'MA'
                                     AND b.ucraddr_status_ind = 'A')

Link to comment
Share on other sites

mamulu from and join condition lo rayachu kada like....%$#$

 FROM ucbcust a

left outer join  ucrtele b on a.ucbcust_cust_code = b.ucrtele_cust_code

left outer join ucraddr c on a.ucbcust_cust_code = c.ucraddr_cust_code and  c.UCRADDR_SEQNO = (SELECT MIN(b.ucraddr_seqno) 
                                                           FROM ucraddr b 
                                   WHERE b.ucraddr_cust_code = ucbcust_cust_code 
                                     AND b.ucraddr_atyp_code = 'MA'
                                     AND b.ucraddr_status_ind = 'A')

Link to comment
Share on other sites

Just now, Doola said:

mamulu from and join condition lo rayachu kada like....%$#$

 FROM ucbcust a

left outer join  ucrtele b on a.ucbcust_cust_code = b.ucrtele_cust_code

left outer join ucraddr c on a.ucbcust_cust_code = c.ucraddr_cust_code and  c.UCRADDR_SEQNO = (SELECT MIN(b.ucraddr_seqno) 
                                                           FROM ucraddr b 
                                   WHERE b.ucraddr_cust_code = ucbcust_cust_code 
                                     AND b.ucraddr_atyp_code = 'MA'
                                     AND b.ucraddr_status_ind = 'A')

oh... ok

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...