mardi 29 mars 2016

MYSQL INSERT based on values from 3 columns

I have a mysql database and I would like to do an SELECT/INSERT based on the conditions of three different numeric fields: (HI, OT and WC).

I want to INSERT into a field called AT the value of the following condition:

HI if HI > OT
else
WC if WC < OT
else 
OT

Something like this, but I cannot seem to get it correct:

INSERT INTO variations (AT)
SELECT

HI if HI > OT
else
WC if WC < OT
else
OT,
FROM archive;

General C++ advises about coding

I've recently stared learning C++ so Im new to all of it, Ive got my fourth "software" under development. Could someone have a look through and give me some constructive criticism on what should I change or keep the same? Any help will help :P Many Thanks

Code:

#include <iostream>
#include <string>
#include <stdlib.h>
#include <fstream>

using namespace std;


void mainmenu();


int choice; 
bool cinfail; 
int confirmation; 
string username, password, password2;

void writetofile(string username){
    ofstream writefile;
    string file = username+".txt";
    writefile.open(file.c_str());
    writefile << password;
    writefile.close();
    mainmenu(); }

void login(){
    cout << "You are being logged in!";}


void registerpassword(){
    cout << "Please enter the password:" << endl;
    cin >> password;
    cout << "Please renter your password:" << endl;
    cin >> password2;
    if (password == password2){
        cin.clear();
        cin.ignore(10000,'\n');
        writetofile(username);
        exit(1);
    }
    else;{
        cout << "Sorry invalid" << endl;
        registerpassword();
    }}


void registerme(){
    cout << "Please enter your username: " << endl;
    getline(cin, username);
    cout << "\nUsername -  \""<< username << "\"\nConfirm? \n\n[1] Yes\n[2] No" << endl;
    cin >> confirmation;
    if (confirmation == 1){
        registerpassword();
    }

    else; {
        cout << "Sorry invalid input, Please try again" << endl;
        cin.clear();
        cin.ignore(10000,'\n');
        registerme();
    }}


void exit(){
    exit(0);}

void mainmenu(){ cout << "Hello, Would you like to log in or register\n[1] Login\n[2] Register\n[3] Exit" <<endl; cin >> choice; do{
    cinfail = cin.fail();
    cin.clear();
    cin.ignore(10000,'\n');

    }while(cinfail == true);{
        switch(choice){
            case 1:
                login();
                break;

            case 2:
                registerme();
                break;

            case 3:
                exit();}}} 

main(){ 
mainmenu(); 
}

Remove an object from an array on a condition

I have a csv file that I've already splitted by line breaks and I've broken it down even more by the commas in the line breaks to give me three things I'm looking for and named them for later use in the program. What I'm looking to do is remove an item if a one of the objects match a certain value.

var values=[];
var output="";
for(i = 0; i < csv_split.length; i++){
    csv_split[i] = csv_split[i].split(',') //Splits the csv file that's already split by new line by commas
                 values[i]={}
    values[i].Name=newline_split[i][1]; //finds the second object and names it values.name
    values[i].Rev=newline_split[i][2]; //finds the third object and names it values.rev
    values[i].URL=newline_split[i][9]; //finds the eighth object and names it values.url
}

This then is used later so I can get a list of just the values I'm looking for.

    for (i=0; i < values.length; i++){
output += values[i].Name + ',';
output += values[i].Rev + ',';
output += values[i].URL+ ',';
output += "\n\n||||||";
}

So what I did was modified this code to the first for loop:

    if (values[i].Rev == "NO ACCESS") {
csv_split[i].splice(0,1);
}

The idea behind this was that if the values.Rev matched to "NO ACCESS" it would remove the entirety csv_split[i], so that later it wouldn't display it in the output.

Running the script now gives the entire output of regardless if values.Rev matches "NO ACCESS" or not. What am I missing with this?

SQL Filter SELECT statement

I need to filter my select statement to only grab a value is a bit value is true. For example

 DECLARE
 @Value AS NVARCHAR(20) = 'Some Value'
 @BIT AS BIT = 1,
 @Stuff AS NVARCHAR(20) = 'Stuff'

 SELECT 
     @Stuff,
     IF @BIT = 1 BEGIN @Value END ELSE BEGIN '' END

Something like this basically. I only want to select the value if its true. I have multiple checkboxes and the data should only pull that data back if the user selects one of those check boxes so I'm using bit's to track if its checked or not. Thanks in advance

IF, then VLOOKUP from another workbook with Conditional Criteria

A change up in my plans has lead to me needing to create a formula that:

  • IF cell G5 = "text" then
  • VLOOKUP cell F5 in workbook C:\test\Test_Workbook_DATE.xlsx (where DATE is actually cell H5 in the current workbook)
  • Sheet is Data_Sheet
  • Vlookup table range, LEFT(A:A, LEN(A:A)-3):C trying to trim A in order to match to F5
  • Return value is from column C in the table range

My attempt so far is:

'=IF(G5="Text",VLOOKUP(F5,"C:\Test\[Test_Workbook"&TEXT(H5,"YYYYMMDD)&".xlsx'!Data_Sheet'!TRIM(A):C,2),)

Problem is, this just returns a blank cell when it should return the number from column C. Any hints on where i'm going wrong/how to get it to work and improve syntax is greatly appreciated!

Symfony : "if" does not work in a twig template

I'm trying to validate the size of an array before print a value, but the if instruction doesn't work. Always pass thought the if.

This is my code:

{% set size = custodian.phoneNumbers|length  %}
{% if size > 3 %}
    {% block phone_number3 %}{{phoneNumbers[2].phoneNumber }}{% endblock %}
{% endif %}

size is equal to 2

I try with this code and does not work as well.

{% set size = true %}
    {% if size == false %}
        {{size}} 
{% endif %}

Please help!!! Thanks in advance.

if statement string comparison

What is that i'm doing wrong over here ? the script by default enters this IF statement & displays the echo statement to exit.

#!/bin/ksh


server=$1
dbname=$2
IFS="
"
if [[ "${dbname}" != "abc_def_data" || "${dbname}" != "abc_def01_data" ]]; then
        echo "Msg: Triggers can only be applied to CMS_JAD:abc_def_data/abc_def01_data!"
        exit 0
fi