?
Solved

Execute sp_MSForEachTable on character value

Posted on 2006-04-20
2
Medium Priority
?
590 Views
Last Modified: 2008-02-01
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!
0
Comment
Question by:mixxie
2 Comments
 
LVL 28

Accepted Solution

by:
rafrancisco earned 2000 total points
ID: 16501725
Try this:

EXEC sp_MSForEachTable '
IF COL_LENGTH(''?'', ''myField'') IS NOT NULL
BEGIN
    PRINT ''?''
    EXEC(''SELECT * FROM ? WHERE myField = ''''abc'''''')
END'
0
 

Author Comment

by:mixxie
ID: 16501784
wow, that's more quotation marks than I tried.... but it works great, thank you! :-)
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ready to get certified? Check out some courses that help you prepare for third-party exams.
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
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.
Suggested Courses

839 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