Search code examples
sql-serversql-like

How can I shorten this LIKE statement in SQL Server?


+ case when 
(
    (
        PYMT.element like '____.T.T-0_______.____.________' or 
        PYMT.element like '____.T.T-K_______.____.________'
    )
    and len(PYMT.element) = 31
) 
then '' 
else '12|'
end

I'm trying to find a more elegant way of doing this like statement. Is there another way of doing it?


Solution

  • Only thing I can see you could do instead is to replace both LIKEs with a single one:

    PYMT.element LIKE '____.T.T-[0K]_______.____.________'
    

    And, as WEI_DBA mentions, you can remove the len(PYMT.element) = 31, as the LIKE handles that already.