mercredi 27 mars 2019

Insert New Records Into Table Using If/Else Statement

I have two SQL Server tables where I need to add records from one table to the next. If the unique identifier already exists in the target table, then update the record to the data coming from source table - If the unique identifier doesn't exist, then insert the entire new record into the target table.

I seem to have gotten the initial part to work where I update the records in target table but the the part where I would INSERT new records does not seem to be working.

if exists (select 1
           from SCM_Top_Up_Operational O
           join SCM_Top_Up_Rolling R ON O.String = R.string)
begin
update O
set    O.Date_Added = R.Date_Added,
      O.Real_Exfact = R.Real_Exfact,
      O.Excess_Top_Up = R.Excess_Top_Up 

from  SCM_Top_Up_Operational O 
join  SCM_Top_Up_Rolling R on O.String = R.String

where O.String = R.string 
and   R.date_added > O.date_added
end

else 

begin
   insert into SCM_Top_Up_Operational (String,Date_Added,Real_Exfact,Article_ID,Excess_Top_Up,Plant)
   select String,Date_Added,Real_Exfact,Article_ID,Excess_Top_Up,Plant
   from SCM_Top_Up_Rolling
end

Checking if all info exists in one record

I am currently making an appointment scheduler. I am looking to execute an if statement if the doctor is available at the selected time and date. The code I currently have is as follows:

def book():
    form = BookAppointment(request.form)
    if request.method == 'POST' and form.validate():
        appointment_date = form.appointment_date.data
        appointment_time = form.appointment_time.data
        appointment_patient_id = form.appointment_patient_id.data
        appointment_doctor_id = form.appointment_doctor_id.data
        appointment_centre_id = form.appointment_centre_id.data
        username = session.get('username', None)

        # Create cursor
        cur = mysql.connection.cursor()

        find_doctor = cur.execute("SELECT * FROM doctors WHERE doctor_id =%s", [appointment_doctor_id])
        find_date = cur.execute("SELECT * FROM appointments WHERE appointment_date =%s", [appointment_date])
        find_time = cur.execute("SELECT * FROM appointments WHERE appointment_time =%s", [appointment_time])
        msg = cur.fetchone()

        # Execute query
        cur.execute("INSERT INTO appointments(appointment_date, appointment_time, patient_id, doctor_id, centre_id, patient_username) VALUES(%s, %s, %s, %s, %s, %s)", (appointment_date, appointment_time, appointment_patient_id, appointment_doctor_id, appointment_centre_id, username))

        if find_doctor == 0 and find_date == 0 and find_time == 0:
            if appointment_date.weekday() == 0 or appointment_date.weekday() == 1 or appointment_date.weekday() == 2 or appointment_date.weekday() == 3 or appointment_date.weekday() == 4:
                # Commit to DB
                mysql.connection.commit()

                # Close connection
                cur.close()

                flash('Appointment made successfully!', 'success')
                return redirect(url_for('book'))

            else:
                error = 'Sorry, appointments cannot be made for a Saturday/Sunday'
                return render_template('/patient/bookappointment.html', error=error, form=form)
        else:
            flash('Appointment unavailable, please select another date or time', 'danger')
            return redirect(url_for('book'))
    return render_template('/patient/bookappointment.html', form=form)

So I want an appointment to be made if there is currently no appointment scheduled with the same doctor at the same date and time. Thanks

How to fix Comparative if statement in PHP?

how are you?

I am trying to compare a simple variable in php, the problem that i am having is at the time to see the result, my code prints the wrong answer. I do not know what could be the problem, i have tried to use different Logical Operators but it did not work.

What could be the problem?

Looking forward to a response and thank you in advance.

<?php

       $code_icon = 'green';

       if ($code_icon == '1030' || '1929' || 'aaa'){
           echo 'eeeooo';
       } elseif ($code_icon == 'banaba' || 'fruit' || 'green') {
           echo 'ayuwokiii';
       } 


Sandbox: http://sandbox.onlinephpfunctions.com/code/950e02ff7520f48ebb63e2fce747433fff2223c8

Column = Row Then Gnatt Chart Scheduling

I want to create vba that looks for a date in a row and return start where it matches the row and column values and outputs a value in the cells where they meet up.

(very confusing, kind of like a gantt chart). The purpose is for a user to input activity with start and finish dates and the "gantt chart" to fill out.

Activity Start Finish 3/13 3/14 3/15 3/16 3/17

Floors 3/14 3/17 (blank) START X X FINISH

Mirror 3/15 3/16 (blank) (blank) START FINISH (blank)

For example the input values:

cell a1: activity, cell b1: start, c1: finish, d1: 3/13, e1: 3/14, f1: 3/15, g1: 3/16, h1: 3/17

cell a2: floors, b2: 3/14, c2: 3/17

cell a3: mirror, b3: 3/15, c3: 3/16

Then I want the output to put start and finish in the rows where they match up.

cell a1: activity, cell b1: start, c1: finish, d1: 3/13, e1: 3/14, f1: 3/15, g1: 3/16, h1: 3/17

cell a2: floors, b2: 3/14, c2: 3/17, e2: START, h2: FINISH

cell a3: mirror, b3: 3/15, c3: 3/16, f3: START, g3: FINISH

Then I also want the areas in between (for floors the 3/15 and 3/16 dates) to be marked with an X.

cell a1: activity, cell b1: start, c1: finish, d1: 3/13, e1: 3/14, f1: 3/15, g1: 3/16, h1: 3/17

cell a2: floors, b2: 3/14, c2: 3/17, e2: START, f2: X, g2: X, h2: FINISH

cell a3: mirror, b3: 3/15, c3: 3/16, f3: START, g3: FINISH

Can I code these if statements more efficiënt? [on hold]

I find myself in alot of situations like these and was wondering if I could code these kind of if statements more efficient?

if (velocity.x > runSpeed)
    {
        velocity.x = runSpeed;
    }

    if (velocity.x < -runSpeed)
    {
        velocity.x = -runSpeed;
    }

    if (velocity.z > runSpeed)
    {
        velocity.z = runSpeed;
    }

    if (velocity.z < -runSpeed)
    {
        velocity.z = -runSpeed;
    }

I have problems with If statement, and what to put inside of it

I will show you the challenge that I need to do. It's about if statement, and what to put inside of it. I have this chalenge:

In next section I will write you my code.

draw = function() {

fill(0, 255, 68); // start color
rect(0, 0, 400, 200);  // the button

// The button text
fill(0, 0, 0);
textSize(30);
text("Press me!", 145, 115);

};

The code is on the left side. On the right side is a rectangle with green background and text "Press me" . The chalengde is:

Buttons often change color when they're pressed, so that the user realizes they've pressed something. In this challenge, you'll change the code so that this button turns red when you press it. For this first step, add an if that colors the button red when you press the mouse anywhere on the canvas.

If condition will only run one condition in R

I am trying to run a if else statement and there is an error where it will only run one condition. The variables in question in my data set are the "away_odds" and "home_odds". In the photo examples, the away_odds will only run the "else condition", while the home_odds will only run the "if condition". How would I fix this so it will run both conditions based on the variable > 50 ?

Photo 1 - code

Photo 2 - Data set