Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6845065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:27:16+00:00 2026-05-27T00:27:16+00:00

I need to write a script to insert data selected from one table into

  • 0

I need to write a script to insert data selected from one table into another. The old table stores a value ‘Yes’ in one column but I want to insert 1 instead of ‘Yes’

Is there any way to do this. In my head this is what I want to do:

insert into new_table (new_col1, new_col2)
values (select from old_table(old_col1, (if old_col2='Yes' then 1 else 0))
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:27:16+00:00Added an answer on May 27, 2026 at 12:27 am

    First: if you base your insert on a SELECT, the must not use the VALUES clause.

    To get a conditional value, use the (ANSI standard) CASE statement:

    insert into new_table (new_col1, new_col2)
    select old_col1, 
           case 
             when old_col2 = 'Yes' then 1 
             else 0 
           end
    from old_table
    

    An Oracle only more compact form would be the decode() statement (but I’d recommend to use the CASE, because it’s more readable and portable to other DBMS as well)

    insert into new_table (new_col1, new_col2)
    select old_col1, 
           decode(old_col2, 'Yes', 1, 0)
    from old_table
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write a bash script to do something as another user and
I need to write a Perl script that pipes input into a Java program.
I need to write a script that insert 1-million records of username or emails
I am trying to get one part of a URL to insert into another.
I need to write a script which will post username and password onto a
I need to write a script for MS Exchange Server 2003 that will analyze
I need to write a script that incrementally keeps track of files and directories
I need to write a java script. This is supposed to validate if the
I need to write a bash script , and would like it to parse
I need to write a shell script to be scheduled to run daily to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.