SQL - problems with inserting record, giving constants and a SELECT statement 
Author Message
 SQL - problems with inserting record, giving constants and a SELECT statement

I have a table with some data.

I have tried this SQL statement:
        INSERT INTO Table1 (Field1, Field2, Field3) SELECT Field5, 0 AS
Field6, 3 AS Field 4 FROM Table2

 I wanted to insert data from some other table and with the data
insert some values which are at all records the same.
How to make this work???!?

Quote:
>===========================================================<  

 | Name  : Marko Perko                                     |

 | WWW   : http://www.*-*-*.com/ |
Quote:
>===========================================================<



Tue, 01 Jun 1999 03:00:00 GMT  
 SQL - problems with inserting record, giving constants and a SELECT statement

Quote:

> I have a table with some data.

> I have tried this SQL statement:
>    INSERT INTO Table1 (Field1, Field2, Field3) SELECT Field5, 0 AS
> Field6, 3 AS Field 4 FROM Table2

>  I wanted to insert data from some other table and with the data
> insert some values which are at all records the same.

From that statement, I'm supposing you want to fill only some fields
of Table1 with the contents of Table2.Field5, the number 0 and the
number 3 in that order. In that case, your statement should read:
        insert into table1 (field1, field2, field3)
                select Field5, 0, 3 from table2

However, if your goal is to fill Table1 with the contents of
Table2.Field5 when Table2.Field6 has 0 and Table2.Field4 has 3,
then your statement should read:
        insert into table1(Field1)
                select Field5 from table2
                where field4=3
                  and field6=0
I left the references to field2 and field3 out of this statement, as I
see no use of a table filled completely with the same data. If you
really want table1 to be filled with default values for field2 and
field3, then take the first statement, adding just the where clause of
the second: constants in the select clause are left as they are in the
result set.

Good luck!

Jasper



Wed, 02 Jun 1999 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Problem with parameters in a Insert sql statement

2. Problem with SQL (INSERT-statement)

3. Phantom records in select statement w/RDO

4. SQL Select Statement

5. SQL Guru: Hard Select statement

6. SQL statement -select from

7. SQL select statement

8. SQL SELECT Statement - HELP!

9. How to retrieve info from an insert SQL statement

10. ADO, BLOB and Paradox problem with Insert statement.

11. SQL question Selecting records by date

12. Q : SQL and INSERT and Multi-Records

 

 
Powered by phpBB® Forum Software