Counting the number of columns in a row

  • I have a need to validate a file and part of this validation is to count how many columns exist in each row (tab-delimited).

    I have tried using the following, which works in most (but not all) cases (example using , as the delimiter for display reasons).

    SELECT * -- Errors

    FROM testTable

    WHERE testLine NOT LIKE '%,%,%,%,[^,]%'

    to check for 5 columns

    Things fall apart once you have a few columns with nothing in them, inc the last column.

    Can anyone suggest a good, preferably set-based method to use instead? I would rather not go down the CURSOR, SUBSTRING route.

    Many thanks for any suggestions - have a good weekend.

  • Load into a dummy table and then move it for rows that have enough non-NULL values?

    Steve Jones

    sjones@sqlservercentral.com

    http://www.sqlservercentral.com/columnists/sjones

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply