scan all the columns if first char is space

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?
LVL 5
25112Asked:
Who is Participating?
 
Aneesh RetnakaranDatabase AdministratorCommented:
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%'
0
 
Anthony PerkinsCommented:
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 ...

0
 
25112Author Commented:
yes
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.