Compare two or more column value randomized fromat using ASCII

Example :-

Create function dbo.fnAnswerUpdate (@UserAnswer nvarchar(1000),@CorrectAnswer nvarchar(1000))

Returns int As Begin

DECLARE @position int, @position1 int, @string varchar(200)

— Initialize the variables.

SET @position = 1

SET @position1 = 1

SET @string = @UserAnswer

Declare @a int set @a=0

WHILE @position <= DATALENGTH(@string)

BEGIN set @a+=(SELECT ASCII(SUBSTRING(@string, @position, 1)))

SET @position = @position + 1

End SET @position1 = 1

SET @string = @CorrectAnswer

Declare @b int

set @b=0

WHILE @position1 <= DATALENGTH(@string)

BEGIN set @b+=(SELECT ASCII(SUBSTRING(@string, @position1, 1)))

SET @position1 = @position1 + 1

End

if(@a=@b)

Begin

set @a=1

End

Else

Begin

set @a=2

End

return @a

End

Go

Select dbo.fnAnswerUpdate(‘A|B|C’,’B|D|A’)

1- Complete

2-Incomplete

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: