cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

BODS - SQL Transform case statement with '%[0-9]%'

0 Likes
2,054

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.

View Entire Topic
werner_daehn
Active Contributor

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.

0 Likes

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.

werner_daehn
Active Contributor
0 Likes

sgilla14 What I would do next is create a job with a single script object and try out the various versions with fixed input text values, e.g.

print(match_simple('1234','*[0-9]*'));

This will allow you to analyze the individual components and figure out what the root cause actually is.