我有一個t-sql腳本可以提取我們網站的成員,但是我在使用*,&或用戶名中有數字的用戶遇到問題。非字母字符
我有例如以下數據:
''Dream A Little Dream''
***Unique Business Card/Sign/Logo Designs***
3D Visual Creations
50dollarbanner.com
etc..
我沿着頁面和用戶的頂部的英文字母可以點擊「A」,例如,它列出了所有的用戶開始用「 A」是有辦法也許再拍爲‘0’,例如,它會列出所有成員開始用數字或奇怪的字符:
這裏是我的測試腳本:
DECLARE @TotalPages INT
DECLARE @UserName varchar(50)
DECLARE @PG INT
DECLARE @PageSize INT
SET @UserName = 'Z'
SET @PG = 1
SET @PageSize = 70
BEGIN
SELECT @TotalPages = COUNT(*)/@PageSize
FROM Member
WHERE (sbuser.sf_GetDisplayName(FirstName, LastName, BusinessName, DisplayNameTypeID) LIKE @UserName + '%')
AND UserName IS NOT NULL;
WITH FindSBMembers AS
(
SELECT ROW_NUMBER() OVER(ORDER BY Claimed DESC, sbuser.sf_MemberHasAvatar(MemberID) DESC) AS RowNum,
MemberID, -- 1
UserName, -- 2
PrCity, -- 3
PrStateID, -- 4
sbuser.sf_MemberHasImages(MemberID) AS MemberHasImages, -- 5
sbuser.sf_MemberHasVideo(MemberID) AS MemberHasVideo, -- 6
sbuser.sf_MemberHasAudio(MemberID) AS MemberHasAudio, -- 7
sbuser.sf_GetDisplayName(FirstName, LastName, BusinessName, DisplayNameTypeID) AS DisplayName, -- 8
ProfileTypeID, -- 9
Zip, -- 10
PhoneNbr, -- 11
PrPhone, -- 12
Claimed, -- 13
@TotalPages AS TotalPages, -- 14
City -- 15
FROM Member
WHERE (sbuser.sf_GetDisplayName(FirstName, LastName, BusinessName, DisplayNameTypeID) LIKE @UserName + '%')
AND UserName IS NOT NULL
-- AND MemberID <> @MemberID
)
SELECT *
FROM FindSBMembers
WHERE RowNum BETWEEN (@PG - 1) * @PageSize AND @PG * @PageSize
ORDER BY Claimed DESC
END
以下是包含腳本的詳細信息:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [sbuser].[sf_GetDisplayName](
@FirstName varchar(50),
@LastName varchar(50),
@BusinessName varchar(50),
@DisplayNameTypeID int)
RETURNS varchar(150) WITH schemabinding
AS
BEGIN
DECLARE @OUT varchar(150)
SET @OUT = ''
SET @FirstName = UPPER(LEFT(LTRIM(RTRIM(@FirstName)), 1)) + RIGHT(LTRIM(RTRIM(@FirstName)), LEN(LTRIM(RTRIM(@FirstName))) - 1)
SET @LastName = UPPER(LEFT(LTRIM(RTRIM(@LastName)), 1)) + RIGHT(LTRIM(RTRIM(@LastName)), LEN(LTRIM(RTRIM(@LastName))) - 1)
SET @BusinessName = UPPER(LEFT(LTRIM(RTRIM(@BusinessName)), 1)) + RIGHT(LTRIM(RTRIM(@BusinessName)), LEN(LTRIM(RTRIM(@BusinessName))) - 1)
IF @DisplayNameTypeID = 2 -- FIRST/LAST NAME
BEGIN
SET @OUT = @LastName + ', ' + @FirstName
END
IF @DisplayNameTypeID = 3 -- FIRST NAME/LAST INITIAL
BEGIN
SET @OUT = @FirstName + ' ' + LEFT(@LastName,1) + '.'
END
IF @DisplayNameTypeID = 4 -- BUSINESS NAME
BEGIN
SET @OUT = @BusinessName + ''
END
RETURN @OUT
END
非常感謝您的幫助。
問候, 保羅
這將有助於知道你的確切問題是什麼。我猜測'&'導致HTML呈現問題(使用'&'),'*'與'LIKE'子句干擾。 – 2011-03-24 19:42:28