Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 compare string value in sqlserver 2005

Author  Topic 

cruxmagi
Starting Member

38 Posts

Posted - 2008-04-24 : 05:37:34

CREATE FUNCTION [dbo].[Compare]
(
@usrVal varchar(100),
@dbVal varchar(100)
)
RETURNS BIT
AS
BEGIN
DECLARE @flag BIT
DECLARE @userStrLen INT
DECLARE @dbStrlen INT
DECLARE @counter INT
--Default assignments
SET @counter=1
Set @userStrLen=len(@usrVal)
Set @dbStrlen=len(@dbVal)

IF (@userStrLen != @dbStrlen)
BEGIN
return 0
END
ELSE
BEGIN
WHILE @counter <= @userStrLen
BEGIN
IF (substring(@usrVal,@counter,1) != substring(@dbVal,@counter,1))
RETURN 0
SET @counter = @counter + 1
END
return 1
END
RETURN @flag
--SELECT dbo.Compare('sqlserver user defined functions','sqlserver is the best backend')
END

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-24 : 05:42:31
Whats your question?
Go to Top of Page

cruxmagi
Starting Member

38 Posts

Posted - 2008-04-24 : 06:18:14
my question is the above procedure will return the integer if string value matches,but i want a function which should return the % of the match,for example
val1 =learn csharp
val2=learning sqlserver is not difficult

i want to get the % of match between those values,both strings are related to "learn"
Go to Top of Page
   

- Advertisement -