on ‎2020 Oct 14 10:37 AM
I have a case statement in SQL
Case when Fieldname like '%[0-9]%' then NULL else Fieldname end as Field
This works fine when the SQL is run by itself, but when embedded on SQL Transform and utilized on a Dataflow, it skips the whole statement and renders Fieldname for Field.
Things I tried
1. I tried to use Match_regex in the Query transform. But since the field does not have a pattern and a number could be any where, that did not work.
2. Tried ifthenelse on Query transform, no luck.
I have looked up all the Q&A and forums could not find a solution, please suggest. Thank you.
Request clarification before answering.
We need to distinct between functions in BODS and in the source database.
When using the SQL transform, the string is passed as-is to the database. Well, almost as-is, it does have the option to use parameter substitution within [] and {} brackets. And if I am right, this is your problem. You need to escape the [].
select ..., Case when Fieldname like '%\[0-9\]%' then NULL else Fieldname end as Field ....Having said that, I would ask myself if a SQL Transform is the wisest option and rather prefer Julian's approach of BODS functions and Query transform. When using an ifthenelse() function, the second parameter - NULL in your case - determines the return type. Not a good idea.
So I would use:
ifthenelse(match_simple(FieldName,'[0-9]')=1, FieldName, null)This should return either the value in the column FieldName if it is a string, its length is one and the char is a single digit number.
Given your initial query, probably a
ifthenelse(match_simple(FieldName,'*[0-9]*')=1, FieldName, null)is what you are actually looking for.
Note: I haven't tested it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for analyzing my issue, you are right [0-9] looking for the range, or checking for numeric values on the field is what is not working. I have tried all that you posted above and unfortunately nothing worked.
So I came up with a user defined function on SQL to check if there are any numeric values on the string. It will slow down my query a bit but that is the closest I could get to, after several hours of trying different DI functions, even tried to use Index(). For everything [0-9] was problem. I will wait to see if i get any other inputs to try before i close this. Thank you again.
Hi there,
have you tried using match_simple?
match_simple(FieldName,'$') = 0You could use it in a query transform as in:
Ifthenelse(match_simple(FieldName,'$') = 0, NULL, FieldName)Regards,
Julian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi there,
I have done some quick tests for you - the above was just out of my head and I did not test it either.
I forgot the single quotes in above Query:
Ifthenelse(match_simple(FieldName,'$') = 0, NULL, FieldName)Also, if you want to turn it around like wdaehn suggested, you can use:
Ifthenelse(match_simple(FieldName,'$') = 1, FieldName, NULL)The dollar sign represents any alphabetic character, including non-English letters, zero or more times.
Also you can use what wdaehn suggested below, but you would need to put it like this:
ifthenelse(match_simple(FieldName,'*[0..9]*')= 0, FieldName, null)
regards,
Julian
| User | Count |
|---|---|
| 8 | |
| 4 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.