Solved

Stored Procedure return string did not match

Posted on 2012-04-13
5
233 Views
Last Modified: 2012-05-01
When i passed value @Message with
1) vulgar words, it did not return 0 (@ReturnString)
2) vulgar words and mobile not start with 010 ..etc, it did not return 8  (@ReturnString)
3) @MobileNumber = 0101231234 , @Message = scsavcasva , did not return 2 , success (@ReturnString)

USE [theDB]
GO
/****** Object:  StoredProcedure [dbo].[SP_InsertMsg]    Script Date: 04/13/2012 11:45:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================  
-- Author:  <Author,,Name>  
-- Create date: <Create Date,,>  
-- Description: <Description,,>  
-- =============================================  
ALTER PROCEDURE [dbo].[SP_InsertMsg]    
 -- Add the parameters for the stored procedure here  
 @BatchNo INT,
 @OrderNo VARCHAR(100),
 @Refno VARCHAR(100),
 @Priority INT,
 @FromID INT,
 @MobileNumber VARCHAR(20),
 @Message VARCHAR(max),
 @InputDate DATETIME,
 @SuccessDate DATETIME,
 @ExpireDate DATETIME,
 @ModemPortNo INT, 
 @ReturnString int OUTPUT
 
AS  

BEGIN 
     SET NOCOUNT ON 
    -- vulgar text filter start
		--set @ReturnString=5
		DECLARE @S varchar(max),@Split char(1), @X xml
		SELECT @S = @Message, @Split = ' '
		SELECT @X = CONVERT(xml,'<root><s>' + REPLACE(@S,@Split,'</s><s>') + '</s></root>')
		DECLARE @vtext int
		--set @vtext=

		set @vtext=(select COUNT(*) from(
		SELECT [tValue] = T.c.value('.','varchar(20)'),vulgarword FROM @X.nodes('/root/s') T(c)
		left join tVulgarTable on T.c.value('.','varchar(20)') =tVulgarTable.vulgarword
		)
		t
		where t.vulgarword is not null)
		print @vtext
		
--Vulgar text filter end
    
     if (@vtext>0)
		begin
			set @ReturnString = 0
			
				INSERT INTO dbo.tSMSSendLog
          ( 
            fBatchNo                     ,
            fOrderNo                     ,
            fRefNo                       ,
            fPriority                    ,
            fFromID                      ,
            fMobileNumber                ,
            fMessage					 ,
            fInputDate					 ,
            fSuccessDate				 ,
            fExpireDate					,
            fSendStatus					,
            fSentToMobileNo				,
            fSentFromModemPortNo		,
            fErrorMsg					,
            fDateAdd					
          ) 
     VALUES 
          ( 
            @BatchNo                      ,
            @OrderNo                      ,
            @Refno                        ,
            @Priority                     ,
            @FromID                       ,
            @MobileNumber                 ,
            @Message                      ,
            @InputDate                    ,
            @SuccessDate                  ,
            @ExpireDate					  ,
            'Failed'				      ,
            @MobileNumber				  ,
            @ModemPortNo				  ,
            'Vulgar Words Detected'		  ,
            GETDATE()										  
          ) 
			
		
		end
		
		 if (@vtext>0 and ((SUBSTRING(@MobileNumber, 0, 3) <> '010') or (SUBSTRING(@MobileNumber, 0, 3) <> '011') or (SUBSTRING(@MobileNumber, 0, 3) <> '012') or (SUBSTRING(@MobileNumber, 0, 3) <> '013') or 
		(SUBSTRING(@MobileNumber, 0, 3) <> '016') or (SUBSTRING(@MobileNumber, 0, 3) <> '017') or (SUBSTRING(@MobileNumber, 0, 3) <> '018') or 
		(SUBSTRING(@MobileNumber, 0, 3) <> '019')))
		begin
			set @ReturnString = 8
			
				INSERT INTO dbo.tSMSSendLog
          ( 
            fBatchNo                     ,
            fOrderNo                     ,
            fRefNo                       ,
            fPriority                    ,
            fFromID                      ,
            fMobileNumber                ,
            fMessage					 ,
            fInputDate					 ,
            fSuccessDate				 ,
            fExpireDate					,
            fSendStatus					,
            fSentToMobileNo				,
            fSentFromModemPortNo		,
            fErrorMsg					,
            fDateAdd					
          ) 
     VALUES 
          ( 
            @BatchNo                      ,
            @OrderNo                      ,
            @Refno                        ,
            @Priority                     ,
            @FromID                       ,
            @MobileNumber                 ,
            @Message                      ,
            @InputDate                    ,
            @SuccessDate                  ,
            @ExpireDate					  ,
            'Failed'				      ,
            @MobileNumber				  ,
            @ModemPortNo				  ,
            'Vulgar Words and invalid mobile number detected'		  ,
            GETDATE()										  
          ) 
			
		
		end
		
	if (len(@Message)>160)
		begin
			set @ReturnString = 1
			
			INSERT INTO dbo.tSMSSendLog
          ( 
            fBatchNo                     ,
            fOrderNo                     ,
            fRefNo                       ,
            fPriority                    ,
            fFromID                      ,
            fMobileNumber                ,
            fMessage					 ,
            fInputDate					 ,
            fSuccessDate				 ,
            fExpireDate					,
            fSendStatus					,
            fSentToMobileNo				,
            fSentFromModemPortNo		,
            fErrorMsg					,
            fDateAdd					
          ) 
     VALUES 
          ( 
            @BatchNo                      ,
            @OrderNo                      ,
            @Refno                        ,
            @Priority                     ,
            @FromID                       ,
            @MobileNumber                 ,
            @Message                      ,
            @InputDate                    ,
            @SuccessDate                  ,
            @ExpireDate					  ,
            'Failed'				      ,
            @MobileNumber				  ,
            @ModemPortNo				  ,
            'More than 160 character detected'		  ,
            GETDATE()										  
          ) 
			
		end
	if (len(@Message)>160 and @vtext>0)
		begin
			set @ReturnString = 3
			
			INSERT INTO dbo.tSMSSendLog
          ( 
            fBatchNo                     ,
            fOrderNo                     ,
            fRefNo                       ,
            fPriority                    ,
            fFromID                      ,
            fMobileNumber                ,
            fMessage					 ,
            fInputDate					 ,
            fSuccessDate				 ,
            fExpireDate					,
            fSendStatus					,
            fSentToMobileNo				,
            fSentFromModemPortNo		,
            fErrorMsg					,
            fDateAdd					
          ) 
     VALUES 
          ( 
            @BatchNo                      ,
            @OrderNo                      ,
            @Refno                        ,
            @Priority                     ,
            @FromID                       ,
            @MobileNumber                 ,
            @Message                      ,
            @InputDate                    ,
            @SuccessDate                  ,
            @ExpireDate					  ,
            'Failed'				      ,
            @MobileNumber				  ,
            @ModemPortNo				  ,
            'More than 160 characters and Vulgar Words Detected'		  ,
            GETDATE()										  
          ) 
			
		end
		
		if ((SUBSTRING(@MobileNumber, 0, 3) <> '010') or (SUBSTRING(@MobileNumber, 0, 3) <> '011') or (SUBSTRING(@MobileNumber, 0, 3) <> '012') or (SUBSTRING(@MobileNumber, 0, 3) <> '013') or
		(SUBSTRING(@MobileNumber, 0, 3) <> '016') or (SUBSTRING(@MobileNumber, 0, 3) <> '017') or (SUBSTRING(@MobileNumber, 0, 3) <> '018') or 
		(SUBSTRING(@MobileNumber, 0, 3) <> '019'))
		
		begin
			set @ReturnString = 5
			
			INSERT INTO dbo.tSMSSendLog
          ( 
            fBatchNo                     ,
            fOrderNo                     ,
            fRefNo                       ,
            fPriority                    ,
            fFromID                      ,
            fMobileNumber                ,
            fMessage					 ,
            fInputDate					 ,
            fSuccessDate				 ,
            fExpireDate					,
            fSendStatus					,
            fSentToMobileNo				,
            fSentFromModemPortNo		,
            fErrorMsg					,
            fDateAdd					
          ) 
     VALUES 
          ( 
            @BatchNo                      ,
            @OrderNo                      ,
            @Refno                        ,
            @Priority                     ,
            @FromID                       ,
            @MobileNumber                 ,
            @Message                      ,
            @InputDate                    ,
            @SuccessDate                  ,
            @ExpireDate					  ,
            'Failed'				      ,
            @MobileNumber				  ,
            @ModemPortNo				  ,
            'Invalid mobile number'		  ,
            GETDATE()										  
          ) 
			
		end 
		
			if (ISNUMERIC(@MobileNumber) = 0)
			begin
			
			set @ReturnString = 7
			
			INSERT INTO dbo.tSMSSendLog
          ( 
            fBatchNo                     ,
            fOrderNo                     ,
            fRefNo                       ,
            fPriority                    ,
            fFromID                      ,
            fMobileNumber                ,
            fMessage					 ,
            fInputDate					 ,
            fSuccessDate				 ,
            fExpireDate					,
            fSendStatus					,
            fSentToMobileNo				,
            fSentFromModemPortNo		,
            fErrorMsg					,
            fDateAdd					
          ) 
     VALUES 
          ( 
            @BatchNo                      ,
            @OrderNo                      ,
            @Refno                        ,
            @Priority                     ,
            @FromID                       ,
            @MobileNumber                 ,
            @Message                      ,
            @InputDate                    ,
            @SuccessDate                  ,
            @ExpireDate					  ,
            'Failed'				      ,
            @MobileNumber				  ,
            @ModemPortNo				  ,
            'Mobile number is alpha-numeric'		  ,
            GETDATE()										  
          ) 
			
			end
		
	
	 if ((len(@Message)<160 or len(@Message)=160) and (((SUBSTRING(@MobileNumber, 0, 3) = '010') or (SUBSTRING(@MobileNumber, 0, 3) = '011') or (SUBSTRING(@MobileNumber, 0, 3) = '012') or (SUBSTRING(@MobileNumber, 0, 3) = '013') or
		(SUBSTRING(@MobileNumber, 0, 3) = '016') or (SUBSTRING(@MobileNumber, 0, 3) = '017') or (SUBSTRING(@MobileNumber, 0, 3) = '018') or 
		(SUBSTRING(@MobileNumber, 0, 3) = '019')) and @vtext = 0))
		begin
			
			set @ReturnString = 2
		
        
     INSERT INTO dbo.tSMSBuffB
          ( 
            fBatchNo                     ,
            fOrderNo                     ,
            fRefNo                       ,
            fPriority                    ,
            fFromID                      ,
            fMobileNumber                ,
            fMessage					 ,
            fInputDate					 ,
            fSuccessDate				 ,
            fExpireDate        
          ) 
     VALUES 
          ( 
            @BatchNo                      ,
            @OrderNo                      ,
            @Refno                        ,
            @Priority                     ,
            @FromID                       ,
            @MobileNumber                 ,
            @Message                      ,
            @InputDate                    ,
            @SuccessDate                  ,
            @ExpireDate
          ) 
        
return @ReturnString
end
END 

Open in new window

0
Comment
Question by:doramail05
  • 2
5 Comments
 
LVL 3

Accepted Solution

by:
Chris__W earned 500 total points
ID: 37843025
Hello,

The 'end' line second up from the last line is putting your only RETURN code inside the TRUE portion of the last IF statement.  

Change the ending to:

end
return @ReturnString
END

Thanks,
Chris
0
 
LVL 3

Expert Comment

by:Chris__W
ID: 37881279
Hello Dormail05,

Did moving the 'return' down below the last 'end' cover it, or did another issue arrise?

Thanks,
Chris
0
 
LVL 1

Author Comment

by:doramail05
ID: 37885700
I've requested that this question be deleted for the following reason:

solved from others
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now