Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2015
    Posts
    31

    Unanswered: one select instead of 5

    Hello,
    I have another question,

    I would like to do just one SELECT instead of the followings...

    insert into table select 'VOI' as cpc_code , fields from t1
    insert into table select 'SMS' as cpc_code , fields from t1
    insert into table select 'EMA' as cpc_code , fields from t1

    something like

    insert into table select cpc_code , fields from t1 where cpc_code in ( 'VOI' , 'SMS' , 'EMA' )

    there is a way to do this ?
    thank you -

  2. #2
    Join Date
    Jul 2013
    Location
    Moscow, Russia
    Posts
    666
    Provided Answers: 55
    What's the error / wrong result you get trying your insert statement?
    Regards,
    Mark.

  3. #3
    Join Date
    Mar 2015
    Posts
    31
    Quote Originally Posted by mark.b View Post
    What's the error / wrong result you get trying your insert statement?
    just want to simplify the code ... instead of having 3 insert , would like to have just one

    insert into table select 'VOI' as cpc_code , fields from t1
    insert into table select 'SMS' as cpc_code , fields from t1
    insert into table select 'EMA' as cpc_code , fields from t1

    thank you -

  4. #4
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    2,514
    Provided Answers: 11
    as per select question in another thread : you have to be more specific, as we can not guess what you want to do..
    Best Regards, Guy Przytula
    Database Software Consultant
    Good DBAs are not formed in a week or a month. They are created little by little, day by day. Protracted and patient effort is needed to develop good DBAs.
    Spoon feeding : To treat (another) in a way that discourages independent thought or action, as by overindulgence.
    DB2 UDB LUW Certified V7-V8-V9-V9.7-V10.1-V10.5 DB Admin - Advanced DBA -Dprop..
    Information Server Datastage Certified
    http://www.infocura.be

  5. #5
    Join Date
    Jul 2013
    Location
    Moscow, Russia
    Posts
    666
    Provided Answers: 55
    My question was about your query below:

    insert into table select cpc_code , fields from t1 where cpc_code in ( 'VOI' , 'SMS' , 'EMA' )
    Regards,
    Mark.

  6. #6
    Join Date
    Mar 2015
    Posts
    31
    I would like to replace 3 insert with just one ...
    instead of
    insert into table_out select 'VOI' as cpc_code , fields from t1
    insert into table_out select 'SMS' as cpc_code , fields from t1
    insert into table_out select 'EMA' as cpc_code , fields from t1
    do something like

    insert into table_out
    select a(i) , t1.name , t1.address
    from t1 , table (values 'EMA', 'SOC', 'VOI', 'SMS', 'POS') a(i)

    then in my output table ( table_out ) I would have

    EMA Jon street1
    SOC Jon street1
    VOI Jon street1
    SMS Jon street1
    POS Jon street1

    thank you

  7. #7
    Join Date
    Jul 2013
    Location
    Moscow, Russia
    Posts
    666
    Provided Answers: 55
    So, what's the problem with the query below?
    Code:
    insert into table_out
    select a.i, t1.name , t1.address
    from t1 , table (values 'EMA', 'SOC', 'VOI', 'SMS', 'POS') a(i)
    Regards,
    Mark.

Posting Permissions

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