欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

Get Profile Property List By UserID

程序员文章站 2022-06-14 10:58:54
...

没什么大用处 无 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