Hello Sebastian,
I modified your script and before I run it, I test to make sure I dont have any errors in it. The section where I have the errors is this:
CREATE FUNCTION dbo.dnn_UserRoleNamesList
(
-- Add the parameters for the function here
@portalID int,
@userID int,
@delimiter nvarchar(10)
)
RETURNS nvarchar(4000)
AS
BEGIN
-- Declare the return variable here
DECLARE @ResultVar nvarchar(4000) = ''
DECLARE @myName nvarchar(50)
DECLARE @delim nvarchar(10) = ', '
DECLARE RoleNames CURSOR LOCAL READ_ONLY FOR
SELECT R.RoleName FROM dbo.dnn_Roles R INNER JOIN dbo.dnn_UserRoles UR On R.RoleID = UR.RoleID WHERE R.PortalID = @PortalID AND UR.UserID = @UserID;
OPEN RoleNames
if not @delimiter is Null SET @delim = @delimiter
FETCH NEXT FROM RoleNames
INTO @myName
WHILE @@FETCH_STATUS = 0
BEGIN
IF Not ISNull(@myName, '') = ''
SET @ResultVar = @ResultVar + ', ' + @MyName
FETCH NEXT FROM RoleNames INTO @myName
END
CLOSE RoleNames
DEALLOCATE RoleNames
if isNull(@ResultVar, '') <> '' SET @ResultVar = Substring(@ResultVar, 3, 4000)
RETURN @ResultVar
END
GO
I am getting error message:
Msg 139, Level 15, State 1, Procedure dnn_UserRoleNamesList, Line 0
Cannot assign a default value to a local variable.
Msg 139, Level 15, State 1, Procedure dnn_UserRoleNamesList, Line 0
Cannot assign a default value to a local variable.
Msg 137, Level 15, State 1, Procedure dnn_UserRoleNamesList, Line 18
Must declare the scalar variable "@delim".
Msg 137, Level 15, State 2, Procedure dnn_UserRoleNamesList, Line 24
Must declare the scalar variable "@ResultVar".
Msg 137, Level 15, State 2, Procedure dnn_UserRoleNamesList, Line 30
Must declare the scalar variable "@ResultVar".
Msg 137, Level 15, State 2, Procedure dnn_UserRoleNamesList, Line 30
Must declare the scalar variable "@ResultVar".
Msg 137, Level 15, State 2, Procedure dnn_UserRoleNamesList, Line 31
Must declare the scalar variable "@ResultVar".
How do I fix this?
Thanks.
|