• To get the length of a column, you can use the following function:

    COLUMNPROPERTY( OBJECT_ID('tablename'),'columnname','PRECISION')

    It seems the query optimizer should evaluate it only once instead of for every row.