Quantcast
Channel: SQL Server Express forum
Viewing all articles
Browse latest Browse all 3319

sql server function returns nothing. Please help

$
0
0

Below are the functions:

        

create function dbo.BuildRecordKey (@str

RefID as nvarchar(500), @strRetID as nvarchar(500), @strFName as nvarchar(500), 
@strLName as nvarchar(500), @strZIPorPolType as nvarchar(500), @strKeyMode as nvarchar(500)) 
returns nvarchar(500)  
AS
begin  

--define variables
declare @strTempString nvarchar(500)

--initiate values
set @strKeyMode = upper(@strKeyMode)

--Determine if we are looking for numeric values only or numbers and letters

SET @strTempString = case 
WHEN @strKeyMode IN ('AUTO/CYCLE', 'CYCLE', 'COMMERCIAL')
THEN  @strRefID + '|' + @strRetID
end
SET @strFName = case
WHEN @strKeyMode IN ('ISNAP', 'ASNAP', 'MOAT', 'TRAVELERS', 'MSA', 'CMAD', 'CAM.SALES', 'iMAD.Boat', 'HISS')
THEN  
ltrim(rtrim((Left(dbo.CleanTheStringAdv(@strFName + '  ', 2) + '  ', 2))))
end
SET @strTempString = case
WHEN @strKeyMode IN ('ISNAP', 'ASNAP', 'MOAT', 'TRAVELERS', 'MSA', 'CMAD', 'CAM.SALES', 'iMAD.Boat', 'HISS')
THEN '' + @strRefID + '|' + @strLName + '|' + @strFName + '|' + @strZIPorPolType

else ''
end

    set @strTempString = upper(@strTempString)--capitalize all values

    set @strTempString = dbo.CleanTheStringAdv(@strTempString, 3)--clean invalid chars except our added pipes "|"

return @strTempString
end

----------------------------------------

        

create function dbo.CleanTheStringAdv (@theString as nvarchar(500), @CleanMode as nvarchar(500)) 
returns nvarchar(500)  
AS
begin  

--define variables
declare @strAlphaNumeric nvarchar(500)  
declare @i int
declare @strChar nvarchar(500)
declare @CleanedString nvarchar(500)

--initiate values
set @CleanedString =''  
set @theString = @theString + ''
SET @i = 1

--Determine if we are looking for numeric values only or numbers and letters

SET @strAlphaNumeric = case @CleanMode
WHEN '1'
THEN  '0123456789'
WHEN '2'
THEN  '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
WHEN '3'
THEN  '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ|'
else '0'

end 

--Search through chars in the string passed to the function

    while (@i <= Len(@theString))

begin
set @strChar = substring(@theString, @i, 1)        
If (charindex(@strChar, @strAlphaNumeric) <>0)--if the current char being reviewed is valid then add it to the new string
begin
set @CleanedString = @CleanedString + @strChar
end
SET @i = @i + 1;
end

return @CleanedString
end

------------------------------------------------------

I tried executing the statement:

select dbo.BuildRecordKey('113573', '47822593100000', 'NA', 'NA', 'NA', 'Auto/Cycle')

but it is not returning anything.

Actually I was expecting the output-  113573|47822593100000

Please help.....


Viewing all articles
Browse latest Browse all 3319

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>