Get ready for BLACK FRIDAY shopping starting in

Forums

ASP

This topic is locked

insert then delete record

Posted 13 Aug 2004 02:09:58
1
has voted
13 Aug 2004 02:09:58 Kenty Ramdatt posted:
Hi,
I have an oracle database, from which i extract telephone numbers which meet a certain criteria. I have created a page which first extracts the info then displays it. The user can now using a checkbox select numbers to be deleted from this list. That functionality works. However what I want to do is to capture certain variables, eg IP address, username and of course the selected numbers, first insert that information into a different table in the database for log purposes, and then delete the selections. Can anyone provide some guidance? I hope I gave enough description of want I would like to achieve.

Cheers

Replies

Replied 19 Aug 2004 13:01:16
19 Aug 2004 13:01:16 Simon Martin replied:
You could try creating a cursor and populating that with the id values you're getting from the tickboxes and then using that to set up an INSERT. After which you run your delete code as before.

I've given a framework for what I think you want below - change the variables and names as you need

-- set up variables for cursor
DECLARE @id int

-- create server side cursor
DECLARE cursor_name CURSOR FOR
SELECT ip, username, selected_numbers
FROM table_name
WHERE id = @id

-- use cursor to loop through 'recordset'
OPEN cursor_name

FETCH NEXT FROM cursor_name
INTO @ip, @username, @selected_numbers

WHILE (@@FETCH_STATUS = 0)
BEGIN

-- add details into relevant table_log
INSERT INTO table_log (ip, username, selected_numbers)
VALUES (@ip, @username, @selected_numbers)

-- get the next record
FETCH NEXT FROM cursor_name
INTO @ip, @username, @selected_numbers

END

-- close
CLOSE cursor_name
DEALLOCATE cursor_name


and then run your delete script


Sharing knowledge saves valuable time!

Simon

[DWMX 2004]|[SQL]|[ASP/VBScript]|[XP-Pro]


Edited by - ganseki on 19 Aug 2004 13:04:18

Reply to this topic