I have a problem with this query, I want to copy some columns and add a new value into the same table but doesn't seem to work right. I can't figure out what is wrong
GO
IF OBJECT_ID('dbo.spInsertCopyDocumentos') IS NOT NULL
DROP PROCEDURE spInsertCopyDocumentos
GO
CREATE PROCEDURE spInsertCopyDocumentos
@IdArtigo int,
@IdNovo int
AS
BEGIN
SET NOCOUNT ON
INSERT INTO hDocumentos (IdArtigo) VALUES (@IdNovo)
SELECT TipoDocumento, NomeDocumento,Dados, Extensao, Observacoes
FROM hDocumentos
WHERE IdArtigo = @IdArtigo
END
It says the TipoDocumento is null but it has values and is an integer... I'm not sure why it says null because if i run the select query it shows the values. Also it has 2 rows, so i might not be sure if this only works for one
EDIT.
I'm copying files from a different record ID hence why i Need @IdNovo here to insert the new value in the foreign key ID column
@IdNovotohDocumentos.IdArtigoand then will return the rows from theSELECTbelow theINSERT.(1 row(s) affected)and then the results of theSELECTstatement. TheINSERTand theSELECTand completely separate.