Looking for a better solution , this query I wrote works for me , I would like to know if there is any better approach or same logic which I could used in the case statement