Get Profile Property List By UserID

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

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