General SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsDatabasesGeneral SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 29th, 2013, 08:38 AM
menssanvi menssanvi is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2013
Posts: 6 menssanvi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 7 sec
Reputation Power: 0
Microsoft access to SQL

I'm trying to recode this access code into sql but getting stocked with these IIF, please help:
--------------

SELECT M_accdi.wh_acc_no, (M_accdi.ACCRD_INT+M_accdi.dr_bal) AS Balance
, M_accdi.IntOnlyInd AS Int_Only_Ind
, IIF(M_accdi.REPAYMT_INTERVAL=3,4
,IIF(M_accdi.REPAYMT_INTERVAL=6,2
,IIF(M_accdi.REPAYMT_INTERVAL=7,52
,IIF(M_accdi.REPAYMT_INTERVAL=12,1
,IIF(M_accdi.REPAYMT_INTERVAL=14,26,12))))) AS Divisor
,((IIF(M_accdi.CNTRACT_MATURITY_DTE IS NULL,M_accdi.NXT_REPRICING_DTE
,M_accdi.CNTRACT_MATURITY_DTE)-#12/31/2012#)/365.25) AS Resid_Mat
, IIF(((IIF(M_accdi.CNTRACT_MATURITY_DTE IS NULL
,M_accdi.NXT_REPRICING_DTE,M_accdi.CNTRACT_MATURIT Y_DTE)-#12/31/2012#)/365.25)<=0,1,
CInt(IIF(M_accdi.REPAYMT_INTERVAL=3,4,IIF(M_accdi. REPAYMT_INTERVAL=6,2
,IIF(M_accdi.REPAYMT_INTERVAL=7,52,IIF(M_accdi.REP AYMT_INTERVAL=12,1
,IIF(M_accdi.REPAYMT_INTERVAL=14,26,12)))))*((IIF( M_accdi.CNTRACT_MATURITY_DTE IS NULL
,M_accdi.NXT_REPRICING_DTE,M_accdi.CNTRACT_MATURIT Y_DTE)-#12/31/2012#)/365.25)
)) AS Num_Payments, M_accdi.acc_dr_int_rte/100 AS acc_dr_int_rte
, M_accdi.repaymt_amt, M_accdi.Var_Ind, M_accdi.DEFAULT
FROM M_accdi;

-----------

Reply With Quote
  #2  
Old April 30th, 2013, 02:05 PM
bitsmed bitsmed is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 11 bitsmed User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 59 m 53 sec
Reputation Power: 0
Talking

Hi,

You didn't mention which dbserver you are moving to, but here are two suggestions.

MSSQL would be something like
Code:
select M_accdi.wh_acc_no
      ,M_accdi.ACCRD_INT+M_accdi.dr_bal as Balance
      ,M_accdi.IntOnlyInd as Int_Only_Ind
      ,case M_accdi.REPAYMT_INTERVAL
          when 3 then 4
          when 6 then 2
          when 7 then 52
          when 12 then 1
          when 14 then 26
          else 12
       end as Divisor
      ,datediff(day,'2012-12-31',isnull(M_accdi.CNTRACT_MATURITY_DTE,M_accdi.NX  T_REPRICING_DTE))/365.25 as Resid_Mat
      ,case
          when datediff(day,'2012-12-31',isnull(M_accdi.CNTRACT_MATURITY_DTE,M_accdi.NX  T_REPRICING_DTE))/365.25<=0 then 1
          else case M_accdi.REPAYMT_INTERVAL
                  when 3 then 4
                  when 6 then 2
                  when 7 then 52
                  when 12 then 1
                  when 14 then 26
                  else 12
               end*(datediff(day,'2012-12-31',isnull(M_accdi.CNTRACT_MATURITY_DTE,M_accdi.NX  T_REPRICING_DTE))/365.25)
       end as Num_Payments
      ,M_accdi.acc_dr_int_rte/100 as acc_dr_int_rte
      ,M_accdi.repaymt_amt
      ,M_accdi.Var_Ind
      ,M_accdi.DEFAULT
  from M_accdi


MySql would be something like
Code:
select M_accdi.wh_acc_no
      ,M_accdi.ACCRD_INT+M_accdi.dr_bal as Balance
      ,M_accdi.IntOnlyInd as Int_Only_Ind
      ,case M_accdi.REPAYMT_INTERVAL
          when 3 then 4
          when 6 then 2
          when 7 then 52
          when 12 then 1
          when 14 then 26
          else 12
       end as Divisor
      ,datediff('2012-12-31',ifnull(M_accdi.CNTRACT_MATURITY_DTE,M_accdi.NX  T_REPRICING_DTE))/365.25 as Resid_Mat
      ,case
          when datediff('2012-12-31',ifnull(M_accdi.CNTRACT_MATURITY_DTE,M_accdi.NX  T_REPRICING_DTE))/365.25<=0 then 1
          else case M_accdi.REPAYMT_INTERVAL
                  when 3 then 4
                  when 6 then 2
                  when 7 then 52
                  when 12 then 1
                  when 14 then 26
                  else 12
               end*(datediff('2012-12-31',ifnull(M_accdi.CNTRACT_MATURITY_DTE,M_accdi.NX  T_REPRICING_DTE))/365.25)
       end as Num_Payments
      ,M_accdi.acc_dr_int_rte/100 as acc_dr_int_rte
      ,M_accdi.repaymt_amt
      ,M_accdi.Var_Ind
      ,M_accdi.DEFAULT
  from M_accdi


The two dbengines vary in functions isnull/ifnull and datediff.
By the way: looks like the sql is calculating years from maturity/repricing date. There are better ways to do this, than divide by 365.25

ps. there might be syntax errors, as I don't have access to dbserver - all hail to Notepad

Reply With Quote
  #3  
Old May 1st, 2013, 04:36 AM
menssanvi menssanvi is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2013
Posts: 6 menssanvi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 7 sec
Reputation Power: 0
Thanks for your help. We are actualy moving to teradata. You mention about a better of doing calculating years from maturity/repricing date than the division by 365.25. ??

Reply With Quote
  #4  
Old May 1st, 2013, 12:30 PM
bitsmed bitsmed is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 11 bitsmed User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 59 m 53 sec
Reputation Power: 0
I have never worked with teradata, but googling the manual, it seems teradata engine doesn't have function ifnull/isnull. Instead you can use coalesce function. This function takes same parameters as ifnull/isnull.

In MSSQL the datediff function can return every item of a given date - ex. datediff(year,'2012-12-31',coalesce(M_accdi.CNTRACT_MATURITY_DTE,M_accdi. NXT_REPRICING_DTE)) will return how many year(s).

Teradata doesn't seem to support the datediff function, but this might work: cast('2012-12-31' as date)-coalesce(M_accdi.CNTRACT_MATURITY_DTE,M_accdi.NXT_ REPRICING_DTE) year

Hope this works out for you.

Reply With Quote
  #5  
Old May 2nd, 2013, 05:22 AM
menssanvi menssanvi is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2013
Posts: 6 menssanvi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 7 sec
Reputation Power: 0
Thanks for your help. It is much appreciated.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesGeneral SQL Development > Microsoft access to SQL


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap