Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Tiago Nader Lana

Erro no SQL.

Recommended Posts

Estou executando um script de criação de uma estrutura de segurança via Asp.Net, e quando rodo o script para criar as tabelas, views e procedures no banco ele me retorna o seguinte erro no código abaixo:

 

IF (@ver > 7)SELECT @SqlToExec = N'CREATE PROCEDURE dbo.aspnet_UsersInRoles_AddUsersToRoles	@ApplicationName  nvarchar(256),	@UserNames		  nvarchar(4000),	@RoleNames		  nvarchar(4000),	@CurrentTimeUtc   datetimeASBEGIN	DECLARE @AppId uniqueidentifier	SELECT  @AppId = NULL	SELECT  @AppId = ApplicationId FROM aspnet_Applications WHERE LOWER(@ApplicationName) = LoweredApplicationName	IF (@AppId IS NULL)		RETURN(2)	DECLARE @TranStarted   bit	SET @TranStarted = 0	IF( @@TRANCOUNT = 0 )	BEGIN		BEGIN TRANSACTION		SET @TranStarted = 1	END	DECLARE @tbNames	table(Name nvarchar(256) NOT NULL PRIMARY KEY)	DECLARE @tbRoles	table(RoleId uniqueidentifier NOT NULL PRIMARY KEY)	DECLARE @tbUsers	table(UserId uniqueidentifier NOT NULL PRIMARY KEY)	DECLARE @Num		int	DECLARE @Pos		int	DECLARE @NextPos	int	DECLARE @Name		nvarchar(256)	SET @Num = 0	SET @Pos = 1	WHILE(@Pos <= LEN(@RoleNames))	BEGIN		SELECT @NextPos = CHARINDEX(N',', @RoleNames,  @Pos)		IF (@NextPos = 0 OR @NextPos IS NULL)			SELECT @NextPos = LEN(@RoleNames) + 1		SELECT @Name = RTRIM(LTRIM(SUBSTRING(@RoleNames, @Pos, @NextPos - @Pos)))		SELECT @Pos = @NextPos+1		INSERT INTO @tbNames VALUES (@Name)		SET @Num = @Num + 1	END	INSERT INTO @tbRoles	  SELECT RoleId	  FROM   dbo.aspnet_Roles ar, @tbNames t	  WHERE  LOWER(t.Name) = ar.LoweredRoleName AND ar.ApplicationId = @AppId	IF (@@ROWCOUNT <> @Num)	BEGIN		SELECT TOP 1 Name		FROM   @tbNames		WHERE  LOWER(Name) NOT IN (SELECT ar.LoweredRoleName FROM dbo.aspnet_Roles ar,  @tbRoles r WHERE r.RoleId = ar.RoleId)		IF( @TranStarted = 1 )			ROLLBACK TRANSACTION		RETURN(2)	END	DELETE FROM @tbNames WHERE 1=1	SET @Num = 0	SET @Pos = 1	WHILE(@Pos <= LEN(@UserNames))	BEGIN		SELECT @NextPos = CHARINDEX(N',', @UserNames,  @Pos)		IF (@NextPos = 0 OR @NextPos IS NULL)			SELECT @NextPos = LEN(@UserNames) + 1		SELECT @Name = RTRIM(LTRIM(SUBSTRING(@UserNames, @Pos, @NextPos - @Pos)))		SELECT @Pos = @NextPos+1		INSERT INTO @tbNames VALUES (@Name)		SET @Num = @Num + 1	END	INSERT INTO @tbUsers	  SELECT UserId	  FROM   dbo.aspnet_Users ar, @tbNames t	  WHERE  LOWER(t.Name) = ar.LoweredUserName AND ar.ApplicationId = @AppId	IF (@@ROWCOUNT <> @Num)	BEGIN		DELETE FROM @tbNames		WHERE LOWER(Name) IN (SELECT LoweredUserName FROM dbo.aspnet_Users au,  @tbUsers u WHERE au.UserId = u.UserId)		INSERT dbo.aspnet_Users (ApplicationId, UserId, UserName, LoweredUserName, IsAnonymous, LastActivityDate)		  SELECT @AppId, NEWID(), Name, LOWER(Name), 0, @CurrentTimeUtc		  FROM   @tbNames		INSERT INTO @tbUsers		  SELECT  UserId		  FROM	dbo.aspnet_Users au, @tbNames t		  WHERE   LOWER(t.Name) = au.LoweredUserName AND au.ApplicationId = @AppId	END	IF (EXISTS (SELECT * FROM dbo.aspnet_UsersInRoles ur, @tbUsers tu, @tbRoles tr WHERE tu.UserId = ur.UserId AND tr.RoleId = ur.RoleId))	BEGIN		SELECT TOP 1 UserName, RoleName		FROM		 dbo.aspnet_UsersInRoles ur, @tbUsers tu, @tbRoles tr, aspnet_Users u, aspnet_Roles r		WHERE		u.UserId = tu.UserId AND r.RoleId = tr.RoleId AND tu.UserId = ur.UserId AND tr.RoleId = ur.RoleId		IF( @TranStarted = 1 )			ROLLBACK TRANSACTION		RETURN(3)	END	INSERT INTO dbo.aspnet_UsersInRoles (UserId, RoleId)	SELECT UserId, RoleId	FROM @tbUsers, @tbRoles	IF( @TranStarted = 1 )		COMMIT TRANSACTION	RETURN(0)END'ELSE

O erro é o seguinte:

 

Server: Msg 141, Level 15, State 1, Line 137

A SELECT statement that assigns a value to a variable must not be combined with data-retrieval operations.

 

 

Alguém poderia me ajudar ?

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.