Click here to Skip to main content
15,910,123 members

Comments by sahmed4 (Top 10 by date)

sahmed4 28-Mar-13 1:32am View    
Maciej los.
Please refer my descriptive problem in the below link and try to find out any solution for updating the records based on role id values

Error in Updating the Sp with splitted values[^]
sahmed4 27-Mar-13 8:36am View    
Yes prasad,
I have did it like tat only for time being ..deleted the current roleids and inserted it again..
sahmed4 27-Mar-13 4:20am View    
Please find out this link
http://www.codeproject.com/Questions/568241/ErrorplusinplusUpdatingplustheplusSppluswithplussp
specified my problem in elaborately...
sahmed4 27-Mar-13 4:18am View    
HI prasad,
Have a look in my table structure

select * from Roles
Id RoleName RoleCode
12 Admin NULL
13 Manager NULL
14 Manager2 NULL

Select * from rights
Id RightId RoleId
22 1 12
23 2 12
24 1 13
25 2 13
26 3 13
27 1 14
28 2 14
29 5 14
30 8 14

If i select Manager2 to Edit then My @RoleId values will be 1 2 5 & 8 now i need to update these values based on passing all these id's as 1 2 5 & 8 individually
sahmed4 27-Mar-13 3:30am View    
Hi.
while Inserting values into table Rights i am getting the Current Auto increment value but how do i do this for update sp if i have @Roles values="1,3,5,7,8," that will insert in as 1 3 5 7 8 individually in all the newly created rows in rights table but while updating how do handle this
This is my Insert Sp
====================
ALTER PROC [C244570_hrms12].[h_AddRole]
(
@RoleName NVARCHAR(MAX),
@Roles NVARCHAR(MAX)
)
AS
DECLARE @RoleID INT,@StartingPos INT,@RecPos INT,@RightId INT
DECLARE @RecSet VARCHAR(500)
BEGIN
INSERT INTO ROLES(RoleName) VALUES(@RoleName)
SET @StartingPos=1
SET @RoleId=(SELECT IDENT_CURRENT('ROLES'))
WHILE @StartingPos<=LEN(@roles)
BEGIN
SELECT @RecPos=CHARINDEX(',',@roles,@StartingPos)
SELECT @RecSet=SUBSTRING(@roles,@StartingPos,@Recpos-@StartingPos)
SET @RightId=@RecSet
INSERT INTO Rights(RightId,RoleId)VALUES(@RightId,@roleId)
SELECT @StartingPos=@RecPos+1
END
END


this is my Update SP
====================
ALTER PROC [C244570_hrms12].[h_UpdateRole]
(
@Id INT,
@RoleName NVARCHAR(MAX),
@Roles NVARCHAR(MAX)
)
AS
DECLARE @RoleId INT,@StartingPos INT,@RecPos INT,@RightId INT
DECLARE @RecSet VARCHAR(500),@Rid NVARCHAR(50)
BEGIN
UPDATE Roles SET RoleName=@RoleName WHERE Id=@Id
SET @StartingPos=1
SET @Rid=(SELECT ID FROM RIGHTS WHERE RoleId=@RoleId)
WHILE @StartingPos<=LEN(@roles)
BEGIN
SELECT @RecPos=CHARINDEX(',',@roles,@StartingPos)
SELECT @RecSet=SUBSTRING(@roles,@StartingPos,@RecPos-@StartingPos)
SET @RightId=@RecSet
UPDATE Rights SET RightId=@RightId,RoleId=@RoleId WHERE Id=@Rid
ENDs
END