문제

I wonder if there is an easy and efficient way in SQL Server 2005 to eliminate replicated characters in a string. Like converting

'ABBBCDEEFFFFG' to 'ABCDEFG'

It really sucks that SQL Server has such a poor string library and no ready-to-use regexp feature...

올바른 솔루션이 없습니다

다른 팁

You can use the CLR functionality built into SQL Server 2005/2008 to get this done by .NET code.

MSDN magazine wrote about it in their February 2007 issue.

If this is not an acceptable solution, here is a UDF that will do the same, mind you this is about two orders of magnitude slower than the CLR solution.

YMMV. This appears to work for your string above. But not ABBBCDEEBBBBG

DECLARE @Numbers TABLE (Num smallint NOT NULL PRIMARY KEY)

INSERT @Numbers (Num)
SELECT TOP 8000
    ROW_NUMBER() OVER (ORDER BY c1.NAME)
FROM
    sys.columns c1

DECLARE @STuff TABLE (Seq varchar(100) NOT NULL PRIMARY KEY)

INSERT @STuff (Seq) VALUES ('ABBBCDEEFFFFG') --works

SELECT
    Single
FROM
    (
    SELECT DISTINCT
        CAST(Single AS varchar(100))
    FROM
       @Numbers N
       CROSS APPLY 
       (SELECT Seq, SUBSTRING(Seq, Num, 1) AS Single FROM @Stuff) S
    WHERE
       Num <= LEN(Seq)
    FOR XML PATH ('')
    ) foo(Single)

SharePoint는 내부적으로 UTC 형식으로 날짜를 저장합니다. 귀하의 문제 가이 문제와 관련 될 수 있다고 생각합니다 :

GetFieldValueASText 메서드는 날짜와 시간 값이 필요합니다. UTC 형식으로, 대부분의 SharePoint Foundation 메소드를 반환하는 방법 데이터 목록 현지 시간에 값을 반환합니다.결과적으로, 언제 목록 데이터에 대한 쿼리 수행 시간 값을 변환해야합니다. 예상 결과를 얻으십시오.UTC 날짜와 시간에 항목을 반환하려면 SPQuery 개체 및 DateSinutc 속성을 true로 설정합니다

SPQuery query = new SPQuery();
query.DatesInUtc = true;
SPListItemCollection listItems = list.GetItems(query);
.

더보기 : http://msdn.microsoft.com/ko미국 / 도서관 / MS442266.ASPX

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top