SQL Server - Doubt and relationship between tables

Asked

Viewed 98 times

1

I have a precedent in my BD in which it makes register material in the database, so far so good, but in the registration process I need to update another table assigning the amount of material to a column x, or y depending on the type of material, I saved and ran the trial.

The relation is the following : I will register material in the table "material", and in the previous one he takes the type of material by the parameter @type(which will be the parameter @typeMaterial) it would add with the current value plus the current collection in the column totalPapel of the table totColetas, but always when executing me returns the result "0 affected lines".. Someone could give me a light or some easier and better way to do it (in case mine is bad)?

Follow the code of proc :

 create proc cadMat /*Cadastra o material no banco de dados Ok!(sistema)*/
@cpfColetor char(12),
@nomeMaterial varchar(30),
@tipoMaterial varchar(8),
@zonaMaterial varchar(10),
@qtdeMaterial float,
@dataRecebimentoMaterial datetime
as
begin
    insert into material values(@nomeMaterial,@tipoMaterial,@zonaMaterial,@qtdeMaterial,@dataRecebimentoMaterial,@cpfColetor,'')
    update coletor 
    set qtdeMatCol +=@qtdeMaterial where cpfCol = @cpfColetor
    update material 
    set material.nomeColMat = coletor.nomeCol from material  join coletor on coletor.cpfCol = material.cpfColMat where material.cpfColMat = @cpfColetor
    update totColetas
    set totalPapel += @qtdeMaterial
end
  • what is your database?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.