Simple SQL Question (Select Current Record Only in a Script)

Status
Not open for further replies.

Digitali

Ars Legatus Legionis
17,810
Subscriptor
I have two simple SQL scripts that I use to transfer data from one table to another after the data's been 'cleaned'.

One table gets the 'dirty' data, a human cleans it up and presses a button on an Access form to transfer the cleaned data to the second and final table.

What I need to do is to allow them to transfer the single cleaned record to the next table one at a time instead of as a batch. The scripts I'm using are;

Code:
INSERT INTO dbo_secondtable
SELECT *
FROM dbo_firsttable;

Of course, this will send the contents of the first table to the second.

Then I use this script to delete them all;

Code:
DELETE *
FROM dbo_firsttable
WHERE listno is null;

Is there anyway to just transfer (and subsequently delete) the current record to the second table instead of * at once?

Thanks guys.

dB
 

reboot

Ars Legatus Legionis
10,818
Originally posted by Digitali:
Is there anyway to just transfer (and subsequently delete) the current record to the second table instead of * at once?

1st, semantics : " select * " doesn't select all records, it selects all columns.
What selects all records is the absence of a where clause.

so that would translate to :

Code:
INSERT INTO dbo_secondtable
SELECT *FROM dbo_firsttable WHERE [key=current_record_key];

followed by :

DELETE *FROM dbo_firsttable
WHERE [key=current_record_key];

..of course you'll need to replace [key=current_record_key] with appropriate fields...
 

Digitali

Ars Legatus Legionis
17,810
Subscriptor
1st, semantics : " select * " doesn't select all records, it selects all columns.
What selects all records is the absence of a where clause.

::lightbulb appears over noggin::

Cool. I had never thought about it.

..of course you'll need to replace [key=current_record_key] with appropriate fields...

When you say 'appropriate fields' do you mean the primary key field?

Thanks for the schoolin'.

dB
 

reboot

Ars Legatus Legionis
10,818
When you say 'appropriate fields' do you mean the primary key field?

Yes.

Sorry, I cannot be more precise because I do not know MS SQL.

We could use some more precision on what happens when you 'clean' a record.

from what you said originally, I would *guess* it sets listno to null ;

I which case you could simply use
Code:
INSERT INTO dbo_secondtable
SELECT *FROM dbo_firsttable
WHERE listno is null;
If my assumption is correct, that would transfer only 'cleaned' records, wheter it be one, two or all of them.

if not, it would be either
Code:
INSERT INTO dbo_secondtable
SELECT *FROM dbo_firsttable
WHERE key = key from current selected (cleaned?) record
(same thing I said originally)

or put in a generic way :

Code:
INSERT INTO dbo_secondtable
SELECT *FROM dbo_firsttable
WHERE <B>key = whatever condition identifies clean records</B>
 

Digitali

Ars Legatus Legionis
17,810
Subscriptor
We could use some more precision on what happens when you 'clean' a record.

from what you said originally, I would *guess* it sets listno to null ;

I which case you could simply use

INSERT INTO dbo_secondtable
SELECT * FROM dbo_firsttable
WHERE listno is null;

If my assumption is correct, that would transfer only 'cleaned' records, wheter it be one, two or all of them.

listno is automatically null. What we need is to transfer the single record. As it is, all of the listno fields will be null.

INSERT INTO dbo_secondtable
SELECT *FROM dbo_firsttable
WHERE key = whatever condition identifies clean records

That's our problem, we need only the individual record that has been cleaned.

Right now we have it setup to where they clean the data, then add all of the records to another table. What's happening is that this is a table that's constantly updated. So, after they've cleaned 50 or 100 records, another 10 or 15 have been added, so when they transfer the records, they will either a) have to make sure that none have been added during cleaning or b) end up appending 'dirty' records. That's why I want to be able to let them do it a record at a time.

Thanks reboot.

dB
 

Deniro

Ars Scholae Palatinae
711
Subscriptor++
Similar to what some have said, when they clean a record could you set the value of a 'clean' field to true or something, then the batch process could only transfer records where this field is true. That way any new records in the table would not be moved since they haven't been cleaned.

For doing it one record at a time, have some identity field that is used to move the record. When the user cleans the record, have a hidden field keep the identity value. When they press the button to move the record, it uses this value in the WHERE clause of the query to move the single record.
 
Status
Not open for further replies.