Query Help :copying rows

artificiality

Registered User.
Local time
Today, 09:57
Joined
Jan 30, 2007
Messages
20
Hi ,

I need to copy rows from a table to a specific location in the same table.

I suppose that it is possible to copy rows from a table to the same table
as followed :

INSERT INTO Table
SELECT * FROM Table
WHERE Condition

How can I insert into a specific location based on another condition. ?

Thanks for the help .
 
The concept of rows in a specific order in the table is not valid (that's spreadsheet thinking). You put them in the order you want when you view them, through queries, forms and reports.
 
OK.
How do I copy rows ( part of the fields) of a table into the same table and filling the other fields with specific data with a single query?
 
You could do what you described, but without the wildcard:

INSERT INTO TableName(Field1, Field2, Field3)
SELECT Field1, Field2, "SpecificData"
FROM TableName
WHERE Whatever
 
OK.
What about the ID field ?The ID field is field1(autonumbered) and there is no way I can know in advance their values for the inserted rows.

Should I do :


INSERT INTO TableName( Field2, Field3)
SELECT Field2, "SpecificData"
FROM TableName
WHERE Whatever

?
 
Yes, you never have to include the autonumber field in the insert.
 
How do we select a specific Date format field ?

i.e Date field is 1/10/2007

Select field1,field2,1/10/2007
Where Condition ?
 
Select field1,field2, #1/10/2007#
 
Thanks.
I figured it out.

What is the problem with the following query :

"INSERT INTO RawData(RunID,fullName,name,category,type,subType,numberOfLines,virtual,date,namespace) SELECT 257 ,fullName,name,category,type,subType,numberOfLines,virtual,#1/3/2007#,namespace WHERE namespace = 'customer.demo' AND RunID = 256" ?
 
No FROM clause for one thing.
 
sqlSt = ""
sqlSt = sqlSt & "INSERT INTO RawData(RunID,fullName,name,category,type,subType, numberOfLines,virtual,date,namespace)"
sqlSt = sqlSt & " SELECT " & RunID & " ,fullName,name,category,type,subType,numberOfLines ,virtual," & "#" & d & "#" & ",namespace FROM RawData "
sqlSt = sqlSt & " WHERE namespace = " & "'" & namespace & "'" & " AND RunID = " & id

id = 256

Why do I get on debug for sqlSt :

"INSERT INTO RawData(RunID,fullName,name,category,type,subType, numberOfLines,virtual,date,namespace) SELECT 257 ,fullName,name,category,type,subType,numberOfLines ,virtual,#1/3/2007#,namespace FROM RawData WHERE namespace = 'customer.demo' AND RunID "

Where is the id value ?
 
Don't know; same place the "=" went, I guess. I assume that

id = 256

is really before that point?
 
Not sure, since it properly picked up the other values. Can you post a sample db?

Bad form to post the same question twice, btw.
 
Not sure; that's what makes it curious. You're near 255 characters, which is the limit for some things, but not string variables. How is that variable declared?
 
Then I'm stumped. I cut and pasted your string into a VBA string, and added a bunch of characters, and it held them fine, so it's not a length problem. No sample available?
 
I removed 2 blank spaces from the string :

sqlSt = ""
sqlSt = sqlSt & "INSERT INTO RawData(RunID,fullName,name,category,type,subType,numberOfLines,virtual,date,namespace)"
sqlSt = sqlSt & " SELECT " & RunID & " ,fullName,name,category,type,subType,numberOfLines,virtual," & "#" & d & "#" & ",namespace FROM RawData"
' sqlSt = sqlSt & " FROM RawData "
sqlSt = sqlSt & " WHERE namespace =" & "'" & namespace & "'" & " AND RunID =" & id


And the result is fine.

I have no idea why the removal of 2 spaces is necessary.
 

Users who are viewing this thread

Back
Top Bottom