I have a PaymentInformation table
ID NAME Start End
1 Tina 1/7/2014 1/17/2014
2 Alice 3/7/2014 3/17/2014
3 John 5/7/2014 5/17/2014
4 Michelle 7/7/2014 7/17/2014
I'm building my SQL query dynamically, like this:
SQLiteDataBaseQueryHolder3 = "INSERT INTO " + SQLiteHelper.TABLE2_NAME + "(" +
"name, Start, End" +
")VALUES('" +
tempName + "'" +
",'" +start + "'" +
",'" + end + "" +
"')" +
" WHERE NOT EXISTS ( SELECT * FROM " +SQLiteHelper.TABLE2_NAME +" WHERE name = '"+
tempName+"' AND Start = '"+Start+"')"
Which gives the following result (formatted for readability):
INSERT INTO PaymentInformation(NAME, Start, End)
VALUES('Tina','01/10/2017','2/10/2017')
WHERE NOT EXISTS (
SELECT *
FROM PaymentInformation
WHERE name = 'Tina' AND duration_start = '01/10/2017'
)
Is this how it should be done? It shouldn't insert if Tina is already in the table with a Start day of 01/10/2017.