When I am going to make a registration I want to, according to the selected category, record an id of the moderator, in the question table.
select idcategoria from tb_pergunta
select idmoderador,idcategoria from tb_moderador
USE [BANCOTESTE]
GO
/****** Object: StoredProcedure [dbo].[ATUALIZAMODERADOR] Script Date: 06/15/2015 13:14:47 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[ATUALIZAMODERADOR]
@IDPERGUNTA INT
AS
BEGIN
DECLARE @IDCATEGORIA INT
DECLARE @IDMODERADOR INT
SELECT @IDCATEGORIA = IDCATEGORIA FROM TB_PERGUNTA WHERE IDPERGUNTA = @IDPERGUNTA
SELECT @IDMODERADOR = IDMODERADOR FROM TB_MODERADOR WHERE IDCATEGORIA = @IDCATEGORIA
UPDATE TB_PERGUNTA SET IDMODERADOR = @IDMODERADOR, BLOQUEIO_PERGUNTA='N', EXCLUIR_PERGUNTA='N' WHERE IDPERGUNTA = @IDPERGUNTA
END