I am receiving a Code in sms like "yyyy/mm-digit" (digit increments with every message). so i want to ensure that the code sent by user is exactly in that format otherwise another action. So how ?
Here is my code to check but it always execute else block, why ? Note: I want it for e.g. "2014/8-digit" kinda pattern , how ? (it changes with respect to year and month)
Here is my little effort but it's throwing dateitme conversion failed error plus it might have other issues too, Help
Alter PROCEDURE TestTrigger AS BEGIN Begin Try Declare @msg as varchar(20) SELECT @msg = '2014/9-1' DECLARE @yyyymm varchar(255) = Convert(Varchar ,(cast(year(@msg) as varchar(255)) + '/' + right(cast(month(@msg) as varchar(255)), 2) )); IF (@msg like @yyyymm + '-[0-9]%' and @msg not like @yyyymm + '-%[^0-9]%' ) BEGIN Print 'Done' END ELSE BEGIN Print 'Not Done' END END TRY BEGIN CATCH Select ERROR_MESSAGE() as ErrorMsg END CATCH END GO