May 21, 2008 at 4:09 am
Hi,
I would like to know how can I make an INSERT in a Stored procedure that receives the values that are going to be inserted. But I don't want to repeat the same values on the same table.
My code is the following one
PROCEDURE [dbo].[InsertarFilasINFO_en_HIST_RESET]
@data datetime,
@reset varchar(9),
@ndispositive int,
@status int,
@errornumber int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
INSERT INTO Telifrais.dbo.Table values (@data, @reset, @ndispositive , @status, @errornumber )
/*Here I don't know how codificate the WHERE if it's possible
WHERE @data, @reset, @ndispositive , @status, @errornumber not in Telifrais.dbo.Table */
END
all the ideas are wellcome
thanks in advance:P
May 21, 2008 at 4:38 am
[font="Verdana"]Better you check the values before insert them into the table. Like
Create Proc {Proc Name}
....
If Not Exists(Select Id From Table Where ID) Then
Begin
{Insert Statement}
End
Else
Begin
{Record already exists}
End
....
try it and let us know.
Mahesh[/font]
MH-09-AM-8694
May 21, 2008 at 6:46 am
Mi table doesn't have any primary keys. It's compound by 5 columns and the table doesn't have any relationship with other tables.
So I need something to don't repeat the same row.
Thanks
May 21, 2008 at 6:54 am
It works but after if (...) goes begin not then.
IF NOT EXISTS (SELECT Data, ResetFinreset, NumeroDeDispositivo, NumeroDeZona, NumeroDeError
FROM Telifrais.dbo.HIST_RESET
WHERE Data = @data AND ResetFinreset = @tipodispositivo AND NumeroDeDispositivo = @numerodedispositivo AND NumeroDeZona = @status AND NumeroDeError = @numerodeerror)
BEGIN
INSERT INTO Telifrais.dbo.HIST_RESET values (@data, @tipodispositivo, @numerodedispositivo, @status, @numerodeerror)
END
Thankyou:D
May 21, 2008 at 7:05 am
Set up a unique index if this is really important.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply