• ricky70rana (7/2/2010)


    Can someone explain me how the script given below is working ?

    Especially the CASE Statement

    The CASE expression (sorry about that, couldn't resist) -or rather the nested CASE expressions- are, as already mentioned, overly complicated.

    Basically, it makes use of LEFT(@Text, Number) to get the first Number characters of the string, then uses CASE to decide if there is a @StringDelimiter somewhere in that last part - if there is, it takes the rightmost bit until the last @SDtringDelimiter, otherwise it takes the whole part.

    The nested CASE are required to prevent out-of-bound errors in the SUBSTRING functions.


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/