Win has asked for the wisdom of the Perl Monks concerning the following question:
and#! perl -w script use strict; use warnings; my $Method; my $number_of_years; $Method = 'DDD_t_s_2222_2222_01_2222'; if $Method =~ /DDD_____%/ { $number_of_years = ($yearto-$yearfrom)+1; } elsif ($Method =~ /DDD_t(.|\d){13}(\d{2})/) { if ($Method =~ /DDD_t(.|\d){14}(\d{1})/) { $number_of_years = $2; } elsif ($Method =~ /DDD_t(.|\d){13}(\d{2})/) { $number_of_years = $2; } }
As at least one of them does not behave as expected.DECLARE @Method AS NVARCHAR SET @Method = 'DDD_t_s_2222_2222_01_2222' DECLARE @number_of_years AS NVARCHAR if @Method LIKE 'DDD_____%' begin SET @number_of_years = (@yearto-@yearfrom)+1 end else if @Method LIKE 'DDD_t%' begin if (SELECT SUBSTRING(@Method, 21, 1)) = 0 begin SET @number_of_years = (SELECT SUBSTRING(@Method, 22, 1)) + end else begin SET @number_of_years = (SELECT SUBSTRING(@Method, 21, 2)) end end
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: SQL and Perl comparison
by pg (Canon) on Oct 27, 2005 at 11:37 UTC | |
by dragonchild (Archbishop) on Oct 27, 2005 at 12:11 UTC | |
by Win (Novice) on Oct 28, 2005 at 09:20 UTC |