#170070 - 2006-11-05 11:54 PM
Re: Mini-Golf
|
Sealeopard
KiX Master
   
Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
|
Okay, I'll post my SQL code, that'll make the task easier to uderstand. However, I just do the conversion from packed decimal to decimal. Still, primitive solution: Code:
CREATE function dbo.convert_COBOL_unpacked_decimals (@amtstring as varchar(255)) returns decimal(18,2) begin declare @amtdecimal integer set @amtdecimal = case when ltrim(rtrim(@amtstring))='' then NULL when right(@amtstring,1)='R' then '-'+left(@amtstring,len(@amtstring)-1)+'9' when right(@amtstring,1)='Q' then '-'+left(@amtstring,len(@amtstring)-1)+'8' when right(@amtstring,1)='P' then '-'+left(@amtstring,len(@amtstring)-1)+'7' when right(@amtstring,1)='O' then '-'+left(@amtstring,len(@amtstring)-1)+'6' when right(@amtstring,1)='N' then '-'+left(@amtstring,len(@amtstring)-1)+'5' when right(@amtstring,1)='M' then '-'+left(@amtstring,len(@amtstring)-1)+'4' when right(@amtstring,1)='L' then '-'+left(@amtstring,len(@amtstring)-1)+'3' when right(@amtstring,1)='K' then '-'+left(@amtstring,len(@amtstring)-1)+'2' when right(@amtstring,1)='J' then '-'+left(@amtstring,len(@amtstring)-1)+'1' when right(@amtstring,1)='}' then '-'+left(@amtstring,len(@amtstring)-1)+'0' when right(@amtstring,1)='{' then '+'+left(@amtstring,len(@amtstring)-1)+'0' when right(@amtstring,1)='A' then '+'+left(@amtstring,len(@amtstring)-1)+'1' when right(@amtstring,1)='B' then '+'+left(@amtstring,len(@amtstring)-1)+'2' when right(@amtstring,1)='C' then '+'+left(@amtstring,len(@amtstring)-1)+'3' when right(@amtstring,1)='D' then '+'+left(@amtstring,len(@amtstring)-1)+'4' when right(@amtstring,1)='E' then '+'+left(@amtstring,len(@amtstring)-1)+'5' when right(@amtstring,1)='F' then '+'+left(@amtstring,len(@amtstring)-1)+'6' when right(@amtstring,1)='G' then '+'+left(@amtstring,len(@amtstring)-1)+'7' when right(@amtstring,1)='H' then '+'+left(@amtstring,len(@amtstring)-1)+'8' when right(@amtstring,1)='I' then '+'+left(@amtstring,len(@amtstring)-1)+'9' else NULL end return cast(@amtdecimal as integer) end Code:
_________________________
There are two types of vessels, submarines and targets.
|
|
Top
|
|
|
|
#170075 - 2006-11-07 11:45 AM
Re: Mini-Golf
|
Lonkero
KiX Master Guru
   
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
something like this you ment? Code:
function a($) if $ = 0 + $ $a=right($,1) $a = "" + abs(left($,~)) + chr(iif($a=0,123+2*(0>$),64+9*(0>$))+$a) else $a = asc(right($,1))-64 $a = $a - $a*($a>18) $ = 0 + (left($,~)+ ($a - 9*($a>9))) $a = $ - 2*$*($a>9 & $a<>59) endfunction
a(1234) ? a("123D") ? a(-1234) ? a("123M") ?
get $
ok, everyone, start golfing. I didn't bother as I need to get back to work.
|
|
Top
|
|
|
|
#170076 - 2006-11-07 07:03 PM
Re: Mini-Golf
|
Lonkero
KiX Master Guru
   
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
hmm... can't test this but this one should be 2 strokes smaller: Code:
function a($) if $ = 0 + $ $a=right($,1) $a = "" + abs(left($,~)) + chr(iif($a,64+9*(0>$))+$a,123+2*(0>$)) else $a = asc(right($,1))-64 $a = $a - $a*($a>18) $ = 0 + (left($,~)+ ($a - 9*($a>9))) $a = $ - 2*$*($a>9 & $a<>59) endfunction
a(1234) ? a("123D") ? a(-1234) ? a("123M") ?
get $
|
|
Top
|
|
|
|
#170079 - 2006-11-08 11:12 PM
Re: Mini-Golf
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11631
Loc: CA
|
Quote:
wtf. I'm the only golfer around? lame.
You're LAME? or the idea that you're the only one coding this round is Lame? 
|
|
Top
|
|
|
|
#170082 - 2006-11-09 04:40 PM
Re: Mini-Golf
|
PaulyT
Fresh Scripter
   
Registered: 2005-08-24
Posts: 8
Loc: Madtown Wisco
|
Code:
Function a($) $array = '{', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', '}', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R' If $ < 0 $a = 10 EndIf $ = Abs($) ? Left($, Len($) - 1) + $array[$a + Right($, 1)] EndFunction
Edited by PaulyT (2006-11-09 04:42 PM)
|
|
Top
|
|
|
|
#170083 - 2006-11-09 05:24 PM
Re: Mini-Golf
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
You can shorten that array assignment a bit: Code:
$array = Split('{ A B C D E F G H I } J K L M N O P Q R')
|
|
Top
|
|
|
|
#170085 - 2006-11-09 06:21 PM
Re: Mini-Golf
|
Benny69
Moderator
   
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
PaulyT, Nice work, don't forget you should dim your vars.
|
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 352 anonymous users online.
|
|
|