Solved

Stored Procedure return string did not match

Posted on 2012-04-13
5
239 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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Nested cursor  in SQL 9 94
SQL Login 17 38
Microsoft Azure SQL - create a read only user 2 13
Extract string portion 2 12
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

919 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

18 Experts available now in Live!

Get 1:1 Help Now