我有一个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
非常感谢你的帮助。
此致 保罗
答案 0 :(得分:0)
如果要包含输入参数@UserName为'0'的非字母起始字符的所有条目,那么您可以尝试下面的WHERE子句(未测试)吗?
这将允许您拥有一个“Misc”类别,您可以通过使用@UserName ='0'
调用该过程来检索该类别 WHERE (
( sbuser.sf_GetDisplayName(FirstName, LastName, BusinessName,
DisplayNameTypeID) LIKE @UserName + '%'
)
OR
(
PatIndex(‘[^A-Za-z]%‘,
sbuser.sf_GetDisplayName(FirstName, LastName, BusinessName,
DisplayNameTypeID) > 0 )
AND
@UserName = '0'
)
)
AND UserName IS NOT NULL
答案 1 :(得分:0)
在开头使用类似的内容(在使用@UserName
的查询之前):
IF @UserName = '0' SET @UserName = '[^a-z]';
如果您的排序规则区分大小写,那么您可能应该使用'[^A-Za-z]'
。