Reputation: 6238
I'm using sqlite3.
In a table "Playlist", I want to Set a new value to the first Null field in a given row (only the first one!).
So for example, here if I were editing the first row, I would want that value to replace the first Null (in column 'Song2') :
____________________________________
**table=Playlist**
____________________________________
id | plname | song1 | song2 | song3| song4..... (<- column names)
____________________________________
1 | Sounds | Alps | Null | Null | Null.....(<- first row)
____________________________________
Whats statement could I use to find the first Null field in a given row, and Set a new value to that field?
Upvotes: 0
Views: 717
Reputation: 42497
You can use a CASE statement for each column. Here is a SQL Fiddle as an example (note: you'd want to replace 'value' with a parameter) http://sqlfiddle.com/#!7/59931/6
Update: I missed the part where you want it to update the first null column. A little trickier, but this version should work: http://sqlfiddle.com/#!7/59931/9
Upvotes: 1