Howt to identify spaces in coulmn

  • Hi Friends

    I got a user requirement like below.

    user wants to know how many address columns have got spaces.

    Example:

    POBOX00-------Here 0 means spaces.

    I know how to trim spaces,dont know how to identify spaces in column.

    Any ideas please?

    Thanks

  • This would return the position of the first space found, 0 if no spaces are found:

    DECLARE @vc_test VARCHAR(255) = 'dlfkal djksfak ldfj'

    SELECT CHARINDEX(' ', @vc_test)

    └> bt



    Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • Thanks for quick response.

    this code is very useful to me ..

  • anitha also watch your data types...if the column is CHAR or NCHAR, it is padded on the right with spaces to the full size of the column definition: insert 'anitha' in a CHAR(50), and it is 6 characters + 44 spaces. you can't remove the spaces either.

    if the column is a varchar, then there's no padding of spaces.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 4 posts - 1 through 3 (of 3 total)

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