lundi 30 mars 2015

Sqlite Update with Substring only returns first row data

I have a table (Raw_Data) with a numerical column (WorkingData).


When I test the following SELECT I return the data I require (1st digit of the numeric value)



SELECT substr([WorkingData], 1, 1) FROM Raw_Data


I now wish to take this value & insert it into another colum in the same table so I try :-



UPDATE Raw_Data SET [FirstDigit] = (SELECT substr([WorkingData], 1, 1) FROM Raw_Data)


This code uses the first digit from the first row & places that value into every row in the the FirstDigit column. Sqlite seems to interperate the SQL command as "identify the first digit of the value found in the first row in the table & use that as the FirstDigit for every subsequent value irrespective of the actual value".



eg of UPDATE comamnd results:-
Row WorkingData First Digit
1 54987 5
2 3267 5
3 19 5


Where am I going wrong with my SQL command please?


Aucun commentaire:

Enregistrer un commentaire