I have a SQLite database on a Windows CE device. It has a column called product_code. The values stored in this column contain both letters and characters. The first character is dependent on the department in which the product is, for example for Draught it would be D, for Spirits S. A sample product_code column entry would be S124 or S09.
On the device, I have a form to add new products to the database. I want the form to be able to generate the next available product code. In order to do that, I need to select the max value of a product_code for a specific department (selected from a combo box).
I have tried using this:
stm = "SELECT MAX(CAST(product_code AS Int)) AS maxPCode FROM product WHERE department_description = '" + cmbDeps.Text.ToString() + "';";
But I get 0 in return. I have also tried:
stm = "SELECT MAX(CAST(product_code AS Int)) AS maxPCode FROM product WHERE product_code NOT LIKE '%[a-z]%' AND ISNUMERIC(product_code) = 1 AND department_description = '" + cmbDeps.Text.ToString() + "';";
But seems like ISNUMERIC() is not a function in SQLite? Is there any other way to get around this problem? I was thinking about possibly using replace(), but not sure if there is a way to strip any letter or if I have to have a condition for each possible department?
Aucun commentaire:
Enregistrer un commentaire