Solved

Stored Procedure return string did not match

Posted on 2012-04-13
5
247 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

726 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