|
-
Oct 7th, 2009, 01:20 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Get values and insert every data continuously using cursor
Hi,
I am using sql server2005. I have an error while executing this sp.
I get the values that @featureoperationmapid and @user id from Users table and need to insert UserPermission table. I am getting error.My error is
"An INSERT statement cannot contain a SELECT statement that assign values to a variable.
Incorrect Syntax near "END". "
DECLARE @userid int
DECLARE @usertypeid int
DECLARE @userpermissionmap varchar(100)
DECLARE @featureoperationmapid int
--Query to get feature name and operation name based on user type
CREATE TABLE #UserPermissionTypes(FK_FeatureOperationMapID int,PK_UserID int)
INSERT INTO #UserPermissionTypes(FK_FeatureOperationMapID,PK_UserID)
SELECT @featureoperationmapid=FeatureUserTypeMapping.FK_FeatureOperationMapID,@userid=Users.PK_UserID
FROM Users INNER JOIN
UserTypes ON Users.FK_UserTypeID = UserTypes.PK_UserTypeID INNER JOIN
FeatureUserTypeMapping ON UserTypes.PK_UserTypeID = FeatureUserTypeMapping.FK_UserTypeID
WHERE (Users.EmailID = @emailid)
DECLARE curInsertUserPermission CURSOR
FOR SELECT * FROM #UserPermissionTypes
OPEN curInsertUserPermission
FETCH NEXT FROM curInsertUserPermission INTO @featureoperationmapid
WHILE @@FETCH_STATUS = 0
BEGIN
INSERT INTO UserPermission (FK_UserID,FK_FeatureOperationMapID)
VALUES (@userid,@featureoperationmapid)
END
CLOSE curInsertUserPermission
DEALLOCATE curInsertUserPermission
END
Please suggest me.
Hope yours reply soon.
Thanks
Failing to plan is Planning to fail 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|