Abhijit writes "I am writing a function called full soundex that finds soundex values of each word in the string seperated by semicolans. I am putting the function here:------------------------------------------------------------IF EXISTS (SELECT * FROM sysobjects WHERE name = 'fn_FullSoundex') --N'<scalar_function_name, sysname, test_function>') DROP FUNCTION fn_FullSoundex --<scalar_function_name, sysname, test_function>GOCREATE FUNCTION fn_FullSoundex --<scalar_function_name, sysname, test_function> (@strIn CHAR(255)) --<@param1, sysname, @p1> <data_type_for_param1, , int>, RETURNS VARCHAR(100) -- <function_data_type, ,int>ASBEGIN DECLARE @OneWord AS VARCHAR(100) DECLARE @iLn AS INT DECLARE @iCount AS INT DECLARE @cChr AS CHAR DECLARE @ThisSoundex AS VARCHAR(100) DECLARE @Soundex AS VARCHAR(100) --PRINT @strIn SET @iCount = 1 SET @iLn = LEN(@strIn) SET @ThisSoundex = '' SET @Soundex = '' SET @OneWord = '' WHILE (@iCount <= @iLn) BEGIN SET @cChr = SUBSTRING ( @strIn,@iCount,1) IF (@cChr = ' ' ) BEGIN -- SET @ThisSoundex = SOUNDEX (@OneWord) SET @Soundex = @Soundex + SOUNDEX (@OneWord) + ';' SET @OneWord = '' END ELSE BEGIN SET @OneWord = @OneWord + @cChr END SET @iCount = @iCount + 1 END IF (@OneWord <> '') BEGIN SET @ThisSoundex = SOUNDEX (@OneWord) SET @Soundex = @Soundex + @ThisSoundex + ';' END RETURN (@Soundex)ENDGO------------------------------------------------------------When I pass "MIRA VINODCHADRA SHAH" to the function it should return: "M600;V532;S000;", Instead it returns "M600;"So I wrote a procedure with the same code and replaced RETURN by PRINT Giving the procedure also:------------------------------------------------------------IF EXISTS (SELECT name FROM sysobjects WHERE name = 'FullSoundex' -- '<procedure_name, sysname, proc_test>' AND type = 'P') DROP PROCEDURE FullSoundex -- <procedure_name, sysname, proc_test>GOCREATE PROCEDURE FullSoundex -- <procedure_name, sysname, proc_test> (@strIn CHAR(255))AS DECLARE @OneWord AS VARCHAR(100) DECLARE @iLn AS INT DECLARE @iCount AS INT DECLARE @cChr AS CHAR DECLARE @ThisSoundex AS VARCHAR(5) DECLARE @Soundex AS VARCHAR(100) --PRINT @strIn SET @iCount = 1 SET @iLn = LEN(@strIn) SET @ThisSoundex = '' SET @Soundex = '' SET @OneWord = '' WHILE (@iCount <= @iLn) BEGIN SET @cChr = SUBSTRING ( @strIn,@iCount,1) IF (@cChr = ' ' ) BEGIN SET @ThisSoundex = SOUNDEX (@OneWord) SET @Soundex = @Soundex + @ThisSoundex + ';' SET @OneWord = '' END ELSE BEGIN SET @OneWord = @OneWord + @cChr END SET @iCount = @iCount + 1 END IF (@OneWord <> '') BEGIN SET @ThisSoundex = SOUNDEX (@OneWord) SET @Soundex = @Soundex + @ThisSoundex + ';' END PRINT @SoundexGO
------------------------------------------------------------Now when I pass "MIRA VINODCHADRA SHAH" to this procedure It prints "M600;V532;S000;". Can anybody guide me where is the mistake. Where am I going Wrong??? Due to this I am stuck very badly."