Convert Decimal to Roman with MSSQL

Today I got assignment to make ms sql function to convert decimal to roman numeral
here’s the code :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Function DecToRom
(
    @InputNumber as varchar(MAX)
)
RETURNS varchar(MAX)
AS
BEGIN
  DECLARE @Hasil varchar(MAX), @RomanLetter varchar(7), @InputTemp bigint, @Posisi int, @Mod bigint
 
  SET @Hasil = ''
  SET @RomanLetter = 'IVXLCDM'

  IF @InputNumber = 0
        SET @Hasil = '0'
  ELSE
  BEGIN
    SELECT @Posisi = 1, @InputTemp = ABS(@InputNumber)
   
    WHILE(@Posisi <= 5)
    BEGIN
        SET @Mod = @InputTemp % 10
        SET @InputTemp = @InputTemp / 10
       
        SELECT @Hasil = CASE
         WHEN @Mod IN (0,1,2,3) THEN        
           Replicate( SubString( @RomanLetter, @Posisi, 1 ), @Mod ) + @Hasil
         WHEN @Mod IN (4) THEN
           SubString( @RomanLetter, @Posisi, 2 ) + @Hasil
         WHEN @Mod IN (5,6,7,8) THEN
           SubString( @RomanLetter, @Posisi + 1, 1 ) +
           Replicate( SubString( @RomanLetter, @Posisi, 1 ), @Mod - 5 ) + @Hasil
         WHEN @Mod IN (9) THEN
           SubString( @RomanLetter, @Posisi, 1 ) + SubString( @RomanLetter, @Posisi + 2, 1 ) + @Hasil
        END
         
        SET @Posisi = @Posisi + 2
    END
   
    SET @Hasil = Replicate('M', @InputTemp) + @Hasil
   
    IF @InputNumber < 0
        SET @Hasil = '-' + @Hasil
       
   END

   RETURN @Hasil
END
GO

credit to sql-bi-dev

WordPress Permalink With IIS 6 Using IIRF

Previously i’m using Isapi_Writer 3.0 from HeliconTech to use permalink for WordPress but sadly it not goes smoothly, i got problem with the permalink, it turn off randomly and get another 404 page, so i try another method, now i try using IIRF (can be download it here) and use this in IIRF.ini :

1
2
3
4
5
6
7
8
9
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d                                
RewriteRule ^/sitemap.xml$   - [L]

RewriteRule ^wp-(.*)$ /wp-$1 [L]
RewriteRule ^xmlrpc(.*)$ /xmlrpc$1 [L]

RewriteRule ^(index.php)*(.*)$ index.php/$2 [NC,L]

Now it’s really fixed, i hope 😀

Update : Again i got another 404 Page
so i change the RewriteRule to

1
RewriteRule ^(index.php)*(.*)$ index.php/$1 [NC,L]

WordPress Permalink With IIS 6

Update : Please see this wordpress-permalink-with-iis-6-using-iirf/ i got problem using isapi_writer 3.0 method.

Ok, After i’m moving my site to the new server that run on windows server 2003, i got problem using the WordPress Permalink. Previously i’m using Windows Server 2008 hosting and got no problem with the permalink, on Windows Server 2008 with IIS 7 and Mod_Writer plugin, i only need to put this on my web.config :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<system.webServer>
        <rewrite>
          <rules>
            <rule name="Main Rule" stopProcessing="true">
              <match url=".*" />
              <conditions logicalGrouping="MatchAll">
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
              </conditions>
              <action type="Rewrite" url="index.php" />
            </rule>
          </rules>
        </rewrite>
</system.webServer>

And when i move to new server, there’s no Mod_Writer for IIS 6, so alternatively i use ISAPI_Rewrite 3.0 from HeliconTech. But When i follow the instruction how to install it in permalink-for-wordpress-iis-6-mod_rewrite-fixed-free, i got 404 Page when i follow my post. So after a week finding solution, i finally see this 404-wordpress-permalinks-iis-with-isapi-rewrite and just put this on my httpd.conf

1
2
3
4
5
6
RewriteBase /
RewriteCond ${REQUEST_FILENAME} !-f
RewriteCond ${REQUEST_FILENAME} !-d
RewriteRule /wp-(.*) /wp-$1 [L]

RewriteRule ^(index.php)*(.*)$ index.php/$2 [NC,L]

and voila… my site is fixed 😀