inserting records from specific columns in one table to another table depending on multiple criteria

Vbasic4now

I'm Using SQL server and need to Inset records from one table into another empty table. the first table im pulling from is called accnt and has the fields: code, invno, invdate, ven, and amnt, and imported. the table that the records are going to is called quick and has the fields: date, num, name, account, split, and amount. some of the fields are just directly copied which i understand, but what im having trouble with is that some of the fields need to be populated with a different field from accnt depending on the value in account. and there is a field in accnt called imported that is either empty or has an x in it. i only want to import records where the imported field is empty

the insert statement i have so far should import: date, name, account, and amount directly not depending on the anything. But the num field imports from a different field in accnt depending on the value of the accno field. the criteria is:

if account < 7000 then num = code if account > 7000 then num = invno

here is what i tried, but it didnt work

DELETE FROM quick
INSERT INTO quick (date, num, name, account, amount) 
if accnt.accno < '7000'
   then SELECT invdate, code, ven, accno, amnt from accnt
if accnt.accno > '7000'
   then SELECT invdate, invno, ven, accno, amnt from accnt

how do i accomplish what i'm trying to do? the table looks like this even though the data in the picture is wrong:

enter image description here

the type and split fields will be populated later with an update query.

Greg Viers

Try it with a single SELECT and use CASE to separate the two situations.

DELETE FROM quick
INSERT INTO quick (date, num, name, account, amount) 
SELECT invdate,
case when accnt.accno < '7000' then code else invno end
, ven, accno, amnt from accnt

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Display records from one table which is not in another table by multiple columns

From Dev

Mysql Query for inserting from one table to another on Multiple conditions and columns

From Dev

Mysql Query for inserting from one table to another on Multiple conditions and columns

From Dev

Pulling records from one table (products) depending on a value in another (department)

From Dev

inserting table values from one table to another

From Dev

Inserting values of one column of a table into different columns of another table

From Dev

Inserting from one database table to another

From Dev

Inserting from one database table to another

From Dev

How do I insert records from one XML file into another at specific points based on multiple criteria?

From Dev

Insert specific rows from one table in database into another with different columns

From Dev

Select / Update records in one table that are LIKE words selected from another table column with multiple records

From Dev

Laravel inserting multiple records in table

From Dev

Copying multiple columns from one SQL table to another

From Dev

Select values from one table depending on referenced value in another table

From Dev

Auto-populate one table from another table if a criteria is met

From Dev

Inserting data to another table based on some criteria

From Dev

Randomly Assign Records From One Table to Another

From Dev

Select from one table if no records found in another

From Dev

Extract one column from sql table and insert into another table as multiple records coupled with different values

From Dev

How to insert multiple records from one table into another on update of third table in MySQL

From Dev

How to get all records from one table and only records from joined table with criteria

From Dev

Selecting one record from two tables and multiple records from another table in ONE query

From Dev

Read (lookup multiple criteria) records from database table, and Write to database table with matching criteria

From Dev

Select records from a table where two columns are not present in another table

From Dev

One record from multiple records in the table

From Dev

Vlookup on another table with multiple criteria

From Dev

Copy specific columns from one table to another table, and include the source tablename

From Dev

How to insert specific columns and rows of data to an existing table from one table to another?

From Dev

Build columns of Yes / No depending on data from another table in mysql

Related Related

  1. 1

    Display records from one table which is not in another table by multiple columns

  2. 2

    Mysql Query for inserting from one table to another on Multiple conditions and columns

  3. 3

    Mysql Query for inserting from one table to another on Multiple conditions and columns

  4. 4

    Pulling records from one table (products) depending on a value in another (department)

  5. 5

    inserting table values from one table to another

  6. 6

    Inserting values of one column of a table into different columns of another table

  7. 7

    Inserting from one database table to another

  8. 8

    Inserting from one database table to another

  9. 9

    How do I insert records from one XML file into another at specific points based on multiple criteria?

  10. 10

    Insert specific rows from one table in database into another with different columns

  11. 11

    Select / Update records in one table that are LIKE words selected from another table column with multiple records

  12. 12

    Laravel inserting multiple records in table

  13. 13

    Copying multiple columns from one SQL table to another

  14. 14

    Select values from one table depending on referenced value in another table

  15. 15

    Auto-populate one table from another table if a criteria is met

  16. 16

    Inserting data to another table based on some criteria

  17. 17

    Randomly Assign Records From One Table to Another

  18. 18

    Select from one table if no records found in another

  19. 19

    Extract one column from sql table and insert into another table as multiple records coupled with different values

  20. 20

    How to insert multiple records from one table into another on update of third table in MySQL

  21. 21

    How to get all records from one table and only records from joined table with criteria

  22. 22

    Selecting one record from two tables and multiple records from another table in ONE query

  23. 23

    Read (lookup multiple criteria) records from database table, and Write to database table with matching criteria

  24. 24

    Select records from a table where two columns are not present in another table

  25. 25

    One record from multiple records in the table

  26. 26

    Vlookup on another table with multiple criteria

  27. 27

    Copy specific columns from one table to another table, and include the source tablename

  28. 28

    How to insert specific columns and rows of data to an existing table from one table to another?

  29. 29

    Build columns of Yes / No depending on data from another table in mysql

HotTag

Archive