Dealing with SQL Server nvarchar’s and perl

As it was a bugger to track down this solution …

Use Encode;
my $dbh = DBI->connect($db->{'source'},$db->{'user'},$db->{'pass'})
or die "{\"error\": Can't connect to $db->{'source'}: $DBI::errstr}";

my $retval = -1;
my $nvarchar;
my $utfchar;
my $sth;
my $maxlen = 4000;

$sth = $dbh->prepare("{ ? = call GetNVARCHAR ( ? ) }");
$sth->bind_param_inout( 1, \$retval, $maxlen );
$sth->bind_param_inout( 2, \$nvarchar, $maxlen );
$sth->execute();

$utfchar = decode("UCS-2LE", $nvarchar );

Finding the date of Easter in T-SQL?

This is based on Al Petrofsky’s 24 operation JavaScript implementation found at http://www.merlyn.demon.co.uk/estralgs.txt and other places

IF EXISTS(SELECT * FROM sys.objects WHERE type = ‘P’ AND name = ‘GetEaster’)
DROP PROCEDURE GetEaster
GO

CREATE PROCEDURE GetEaster
@Year int
AS
BEGIN
DECLARE @tmp_yr int, @tmp_a int, @tmp_b int, @tmp_c int, @e_month int, @e_day int;
— calculate easter using the Al Petrofsky method.
SELECT @tmp_yr = @Year
SELECT @tmp_a = (@tmp_yr / 100) * 2267 – (@tmp_yr / 400) * 6775 + 3411;
SELECT @tmp_b = (@tmp_yr % 19 * 6060 + (@tmp_a / 25) * 319 – 1) % 9570 / 330;
SELECT @tmp_c = 120 + @tmp_b – ((@tmp_yr * 5 / 4) + @tmp_a + @tmp_b) % 7;
SELECT @e_month = (@tmp_c / 31);
SELECT @e_day = @tmp_c % 31 +1;
PRINT ‘Easter for ‘ + CAST(@tmp_yr AS varchar(4)) + ‘ falls on ‘ + CAST(@e_day AS varchar(2)) + ‘/’ + CAST(@e_month AS varchar(2));
END
GO