I have a report that is querying a transaction table, I have simplified the table below:
CREATE TABLE [dbo].[NL_Trans](
[NT_PRIMARY] [int] NOT NULL,
[NT_CODE] [varchar][20] NOT NULL,
[NT_CAT1] [varchar](6) NOT NULL,
[NT_CAT2] [varchar](6) NOT NULL,
)
Data in the table is like:
NT_PRIMARY -- NT_CODE --- NT_CAT1 --- NT_CAT2
---------------------------------------------
1 AB100 123 234
2 AB200 124 234
3 AB300 125 235
4 AB400 126 235
The table has several years data and has 8 NT_CAT fields, these are numbers stored as varchar’s.
I have a large list of categories to limit the query to but I can’t find a way to limit this to ranges of text.
So far I have tried:
{NL_Trans.NT_CAT1} IN "124" to "125"
AND
(CDbl ({NL_Trans.NT_CAT1}) IN 124 to 125))
Neither of which are returning any results.
I can’t use a large list of OR statements as the ranges are more than 100 items in some cases meaning I’d need thousands of lines.
Can anyone give an alternative that will work (and leverage the Catagories index if possible) or tell me why either of the statements above are not working?
First of all, you cannot trust Crystal to evaluate a statement like
"5" in "1" to "10". I don’t know the basis for these comparisons, but I would guess that it is based on ascii values of the leading digits or something like that.With that being said, converting to a double should work… Is it possible you have non-numeric characters in your NT_CAT fields? You should try something like this in your record selection formula and see if you have better luck:
if not(isnull({NL_TRANS.NT_CAT1})) and isnumeric({NL_TRANS.NT_CAT1}) then cdbl({NL_TRANS.NT_CAT1}) in 124 to 125The downside to this is that Crystal won’t add this to the WHERE-clause to be handled on the SQL Server, it will do the selection on the local machine instead. To get around that performance hit, you can create a SQL Expression in Crystal that will do the string-to-numeric conversion for you. I don’t use TSQL so I’m not going to try and convert my Crystal code snippet to it, but if you created the SQL Expression {%ConvertCAT1ToNumeric} you could just use this in your selection formula:
not(isnull({%ConvertCAT1ToNumeric})) and {%ConvertCAT1ToNumeric} in 124 to 125Good luck.