[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Stored Procedure return string did not match

Posted on 2012-04-13
5
Medium Priority
?
263 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 1500 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
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…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

650 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