我遇到了一个存储过程的问题,该过程将内置的C#角色和成员资格管理表中的信息提取到我自己定制的表中。该过程可以正常工作,直到最后一个Update语句。
ALTER PROCEDURE [dbo].[GetPerpsectiveMemberList]
AS
DECLARE @Members TABLE
(
RowNumber INT,
PerspectiveMemberID INT,
FirstName varchar(MAX),
LastName varchar(MAX),
[Address] varchar(MAX),
City varchar(MAX),
[State] varchar(MAX),
Zip varchar(MAX),
Email varchar(MAX),
ASPMemberID varchar(MAX),
ASPUsername varchar(MAX),
RoleID2 varchar(MAX),
RoleName2 varchar(MAX)
)
INSERT INTO @Members
SELECT ROW_NUMBER() OVER (ORDER BY Perspective_Member.PerspectiveMemberID), PerspectiveMemberID, Perspective_Member.FirstName, Perspective_Member.LastName,
Perspective_Member.[Address], Perspective_Member.City, Perspective_Member.[State], Perspective_Member.[State], Perspective_Member.Zip, Perspective_Member.ASPMemberID,
Perspective_Member.ASPUsername,PerspectiveMemberID, ASPMemberID
FROM Perspective_Member
UPDATE @Members
SET RoleID2 = aspnet_UsersInRoles.RoleId
FROM aspnet_UsersInRoles
WHERE ASPMemberID = UserId
UPDATE @Members
SET RoleName2 = RoleName
FROM aspnet_Roles
WHERE RoleID2 = RoleID
SELECT * FROM @Members
当程序失败时,我收到此消息
Conversion failed when converting from a character string to uniqueidentifier.
当我搜索此错误消息时,我发现每个人都遇到了从字符串到唯一标识符的问题,但令我发疯的是,在WHERE子句中使用了最后一个块中使用的唯一唯一标识符,正如我之前所说,只要最后一次UPDATE bl
,程序就会完美运行答案 0 :(得分:3)
您有Perspective_Member。[州]列出两次:
Perspective_Member.[State], Perspective_Member.[State]
这是更正的INSERT语句:
INSERT INTO @Members
SELECT ROW_NUMBER() OVER (ORDER BY Perspective_Member.PerspectiveMemberID),
PerspectiveMemberID,
Perspective_Member.FirstName,
Perspective_Member.LastName,
Perspective_Member.[Address],
Perspective_Member.City,
Perspective_Member.[State],
Perspective_Member.Zip,
Perspective_Member.Email,
Perspective_Member.ASPMemberID,
Perspective_Member.ASPUsername,
PerspectiveMemberID,
ASPMemberID
FROM Perspective_Member
此外,您应该将@Members表中的ASPMemberID和RoleID2字段的数据类型更改为uniqueidentifier
。
更新:似乎错误是由于PerspectiveMemberID
值(INT)被插入RoleID2列(uniqueidentifier)。