0

次の2つの文字列があります。

[DATEREMIND] = {'20/10/2013' -> ^/} [EVENTDATE] = {^ -> '20/10/2013'/} [OCCURREDFLAG] = {0 -> 1/}    
[EVENTDATE] = {^ -> '20/10/2013'/} [DATEREMIND] = {'20/10/2013' -> ^/} [OCCURREDFLAG] = {0 -> 1/} 

これらはまったく同じ内容ですが、順序が異なります。

これら 2 つの文字列を比較して、等しいと見なす簡単な方法はありますか? 日付は変更される可能性がありますが、長さは変更されないため、長さを比較することはできません。

4

1 に答える 1

0

I solved this by creating a function that first converts each character to its ASCII value and subsequently totals up the values of all the digits in the ASCII representation.

Function as follows:

create function dbo.getAsciiRepresentation
(
    @string varchar (max)
)
returns int
as
BEGIN
DECLARE @position int, @aux char(3), @myvalFirst varchar(2000)='1' 
DECLARE @intOfVal bigint
declare @total int, @myval varchar(2000)='1'
SET @position = 1            
WHILE @position <= DATALENGTH(@string)
BEGIN
SET @aux = ASCII(SUBSTRING(@string, @position, 1)) 
SET @myvalFirst = @myvalFirst+ replace(@aux,' ','0')
SET @position = @position + 1
END

set @myval = @myvalFirst
set @position = 1    
set @total = 0
WHILE @position <= DATALENGTH(@myval)
BEGIN
set @aux = SUBSTRING(@myval, @position, 1)
set @total = @total + cast(@aux as int)
SET @position = @position + 1
END
return @total
END

This will then return the same value as long as the same characters are present, regardless of the order.

于 2013-10-24T13:44:57.843 に答える