I may be trying it wrong. I am looking for any approach which is best.
Requirement:
My Query joins 4-5 tables based on few fields.
I have a column called product id. In my table there are 1.5 million rows. Out of those only 10% rows has product ids with the following attribute
A300X-%
A500Y-%
300,500, 700 are valid model numbers. X and Y are classifications. My query picks all the systems.
I have a check as follows
CASE
WHEN PID LIKE 'A300X%'
THEN 'A300'
...
END AS MODEL
Similarly
CASE
WHEN PID LIKE 'A300X%'
THEN 'X'
...
END AS GENRE
I am looking for the best option from the below
- How do I Combine both case statement and add another[third] case which will have these two cases. i.e
CASE WHEN desc in ('AAA') First Case Second Case ELSE don't do anything for other systems END
Is there any regex way of doing this? Before first - take the string. Look for X, Y and also 300,500,700.
Is there any other way of doing this? Or doing via code is the best way?
Any suggestions?
EDIT:
Sample desc:
AAA,
SoftwARE,
sw-app
My query picks all the desc. But the case should be running for AAA alone.
And Valid models are
A300X-2x-P
A500Y-5x-p
A700X-2x-p
A50CE-2x-P
I have to consider only 300,500,700. And the above two cases.
Expected result:
MODEL GENRE
A300 X
A500 Y
A300 Y
CASEexpressions, then it isn't clear why you want just a single column.%functions as a wildcard, meaning that123abcdefg%and123456789dfdgffdgwill both match123%(in connection to alike).case when. So please show the expected result, i.e. not only a list of strings, but also the columns the result shall contain. Will there be a model column? Will there be a genre column? Will there be another column combining these somehow? Please show.