Group by custom expression

hbrems

has no clue...
Local time
Today, 21:25
Joined
Nov 2, 2006
Messages
181
I'm trying to run a query with a custom built function 'StripNumbers'. This function removes any numbers from a string and returns a string as result.

This works:

Code:
SELECT StripNumbers(pt.Code2) AS Program
FROM Primary_Transformants AS pt

The same function with DISTINCT added returns a data type mismatch error.

Code:
SELECT DISTINCT StripNumbers(pt.Code2) AS Program
FROM Primary_Transformants AS pt

I get the same error with a GROUP BY clause.

Code:
SELECT StripNumbers(pt.Code2) AS Program
FROM Primary_Transformants AS pt
GROUP BY StripNumbers(pt.Code2)

Can anyone help me understand where the problem lies so I can work around it?
 
I've solved my own problem. In case where a field was empty the function would return #error. I can't group by #error. Lesson learned!

So as a solution I could add an nz statement to turn empty values into empty strings. Or I could update my function to return an emtpy string in case something goes wrong.

Code:
SELECT DISTINCT StripNumbers(nz(pt.Code2, "")) AS Program
FROM Primary_Transformants AS pt
 

Users who are viewing this thread

Back
Top Bottom