I have a ProjectNum column
that contains a string data type
. Normally the numbers are X1234...
but if there is no number assigned, then one must be autogenerated and depending on the priority assigned to the project depends whether it begins with C or F
. So an autogenerated number must begin with C or F
and be followed by six digits and also auto-increment. So here is my query...
SELECT MAX(CINT(RIGHT(ProjectNum, 6))) AS LastDigits
FROM project_master_query
WHERE ((ProjectNum LIKE (IIF([@priorityDefID] = 4, "C*", "F*"))));
This allows me to grab the last auto-incremented number and then I can autogenerate a number in code by adding 1. The issue is, when I send in @priorityDefID of 4
(and at the moment there are none in the database that begin with "C"), I receive the error "This expression is typed incorrectly, or it is too complex to be evaluated.
For example, a numeric expression may contain too many complicated elements. Try simplifying the expression by assigning parts of the expression to variables."
Not quite sure why this comes up with I pass 4, but a 1, 2 or 3 work fine and return the correct value. I was thinking of instead of writing MAX
, just grabbing all of them that begin with C or F and then grab the right 6 digits, order by descending and grabbing the top 1?