Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2011
    Posts
    48

    Unanswered: Question Regarding SQL Insert Into

    Hi,

    I have the following SQL statement.

    INSERT INTO fistry (asscomp_code, rein_acct_id)
    SELECT Mirror.asscomp_code, 9022.22
    FROM mirror
    where rein_acct_id = '9022.00'
    and asscomp_code = '149'
    ;

    But I also want to include that if asscomp_code = '338' then it should insert 9022.11 so it would be like :

    INSERT INTO fistry (asscomp_code, rein_acct_id)
    SELECT Mirror.asscomp_code, 9022.11
    FROM mirror
    where rein_acct_id = '9022.00'
    and asscomp_code = '338'
    ;


    Am I able to combine the two in one sql statement?

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    INSERT 
      INTO fistry 
         ( asscomp_code
         , rein_acct_id )
    SELECT asscomp_code
         , IIF(asscomp_code = '149', 9022.22, 9022.11)
      FROM mirror
     WHERE rein_acct_id = '9022.00'
       AND asscomp_code IN ( '149' , 338' )
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Sep 2011
    Posts
    48
    thanks!! helped a lot

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •