Hey there,
ok, it took me a while, but I successfully wrote a script that will move data from 1 table to a second, identical table. Good for me.
However, I have a lot of NULL’s in the original table that I need to maintain when it gets moved to the new table. Right now, my script puts 0’s in. Can’t have that.
Here is my query string:
$query = ("INSERT INTO $table2 (Year, Event, EventType, Division, Handler, Dog, Club, CR1, D1, I1, S1, C1, deduct1, FS1, CR2, D2, I2, S2, C2, Total) VALUES ('$Year', '$Event', '$Type', '$Division', '$Handler', '$Dog', '$Club', '$CR1', '$D1', '$I1', '$S1', '$C1', '$deduct1', '$FS1', '$CR2', '$D2', '$I2', '$S2', '$C2', '$Total') ");
As I said, that script works fine, except that anything that is NULL becomes ‘0’.
Now, I have another script that I use to directly input data into a table, and if any of the fields are blank, they stay as NULL. Here is what it looks like:
$query = ("UPDATE {$table} SET cr1=IF('$CR1'='',NULL,'$CR1'), D1=IF('$D1'='',NULL,'$D1'), I1=IF('$I1'='',NULL,'$I1'), S1=IF('$S1'='',NULL,'$S1'), C1=IF('$C1'='',NULL,'$C1'), Total='$Total' WHERE row_id=$rowid");
This also works. (yes, the fields are different-they are two different scripts…)
So obviously the difference is one is an INSERT statement, and one is an UPDATE statement. Is there any way to put that ‘IF’ logic into the INSERT statement?
It would be terribly handy!
I have beat my head on this one (including trial error and searches) for a while now…
Any would be greatly appreciated!