Home >Database >Mysql Tutorial >Get Profile Property List By UserID

Get Profile Property List By UserID

WBOY
WBOYOriginal
2016-06-07 14:57:211250browse

没什么大用处 无 CREATE FUNCTION GetProfilePropertyList(@userID uniqueidentifier)RETURNS @propertyTable TABLE(PropertyName varchar(250),PropertyValue varchar(250))BEGINDECLARE @count int = 0DECLARE @pName varchar(250)DECLARE @pStartIndex int

没什么大用处
CREATE FUNCTION GetProfilePropertyList
(
	@userID uniqueidentifier
)
RETURNS 
@propertyTable TABLE
(
	PropertyName varchar(250),
	PropertyValue varchar(250)
)
BEGIN
	DECLARE @count int = 0
	DECLARE @pName varchar(250)
	DECLARE @pStartIndex int
	DECLARE @pLen int
	
	DECLARE @propertyNames varchar(1000)
	DECLARE @propertyValues varchar(1000)
	
	SELECT @propertyNames = PropertyNames,
		   @propertyValues = PropertyValuesString
	From aspnet_Profile
	Where UserId = @userID
	
	WHILE(LEN(@propertyNames) > 0)
	BEGIN
		DECLARE @index int
		DECLARE @prop varchar(250)
		SELECT @index = CHARINDEX(':', @propertyNames)
		SELECT @prop = SUBSTRING(@propertyNames, 0, @index)
	 
		SELECT @propertyNames = SUBSTRING(@propertyNames, @index + 1, LEN(@propertyNames))
		
		SELECT @count = @count + 1
		IF(@count % 4 = 1) SELECT @pName = @prop
		IF(@count % 4 = 3) SELECT @pStartIndex = CAST(@prop AS INT)
		IF(@count % 4 = 0) 
		BEGIN
			SELECT @pLen =  CAST(@prop AS INT)
			INSERT INTO @propertyTable VALUES (@pName, SUBSTRING(@propertyValues, @pStartIndex + 1, @pLen))
		END
				
	END
END
 
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn