scan all the columns if first char is space

Posted on 2011-10-07
Last Modified: 2012-05-12
is there a way to loop through the data of a table - for each string column and see if the first character of the string field is a space?
Question by:25112
    LVL 75

    Accepted Solution

    this will generate the necessay sql, you can copy the results and run it

    select 'select * from '+table_name +' where '+column_name +' like '' %''  ' from information_schema.columns  where table_name = 'yourTableName'
    and data_type like '%char%'
    LVL 75

    Assisted Solution

    by:Anthony Perkins
    It would be a lot faster to spell out all the string columns in a query then resort to building a complex query using Dynamic SQL to do the same.  In other words if you can take the time to write this out it would be faster and less error prone:

    SELECT *
    FROM YourTableName
    WHERE YourStringCol1 LIKE ' %'
                 OR YourStringCol2 LIKE ' %'
                 OR YourStringCol3 LIKE ' %'
                 OR ...

    LVL 5

    Author Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
    Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
    Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
    Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now