Execute sp_MSForEachTable on character value

Hello, experts!  The code below is working great for integers, but the problem is I now need to query for character values.  I've tried every variation of single and double quotations that I can think of, to no avail.  

EXEC sp_MSForEachTable '
IF COL_LENGTH(''?'', ''myField'') IS NOT NULL
BEGIN
    PRINT ''?''
    EXEC(''SELECT * FROM ? WHERE myField = abc)
END
'
Any help is greatly appreciated!
mixxieAsked:
Who is Participating?
 
rafranciscoCommented:
Try this:

EXEC sp_MSForEachTable '
IF COL_LENGTH(''?'', ''myField'') IS NOT NULL
BEGIN
    PRINT ''?''
    EXEC(''SELECT * FROM ? WHERE myField = ''''abc'''''')
END'
0
 
mixxieAuthor Commented:
wow, that's more quotation marks than I tried.... but it works great, thank you! :-)
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.