I am setting a stored procedure for select and I want to update the value of one column in the database Before doing the Select.
This is what I tried but it’s not working.
@roleID int
and @query varchar(240)
SELECT EP.Equipe_Projet_Id AS PROJET_ID, U.USR_ID, CleRepartition = CASE WHEN @RoleID = 1 AND @query IS NOT NULL THEN 100 AND (UPDATE EQUIPE_PROJET SET CleRepartition = 100 WHERE EP.Equipe_Projet_Id = @PROJET_ID AND EP.Role_Id = 3) ELSE NULL END FROM [EQUIPE_PROJET] EP
Expecting update of column on database and having it’s value
Advertisement
Answer
Stored procedure can do update then select after.
So I added the query of update in the beginning, then I do the select.
Like this:
UPDATE EP SET CleRepartition = CASE WHEN @RoleID = 1 AND @query IS NOT NULL THEN 100 AND (UPDATE EQUIPE_PROJET SET CleRepartition = 100 WHERE EP.Equipe_Projet_Id = @PROJET_ID AND EP.Role_Id = 3) ELSE NULL END FROM [EQUIPE_PROJET] EP SELECT EP.Equipe_Projet_Id AS PROJET_ID, U.USR_ID, CleRepartition FROM [EQUIPE_PROJET] EP
I hope that this will help someone.