lundi 6 juillet 2015

how to only insert records into table 2 when field in table 1 is empty

Im using sql server and need to insert into a table based on multiple criteria. i know how to do this part. however, the table im pulling from, called accnt, has an "imported" column that either is blank or has an x in it. I only want to insert the records from accnt into table 2, called quick, if the imported column is empty aka its value is ''. the code below is what I have tried, but it doesnt work. the insert statement without trying to tell it to only insert where imported = '' works fine

IF accnt.imported = ''
then (
   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 
)

I also tried:

WHEN accnt.imported = ''
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

how do i get this concept to work?

Aucun commentaire:

Enregistrer un commentaire