Microsoft Dynamics GP Developing for Dynamics GP
A blog dedicated to the Microsoft Dynamics GP Developer & Consultant community
 
Welcome to MSDN Blogs Sign in | Join | Help

Developing for Dynamics GP

by David Musgrave (Australia) and the Microsoft Dynamics GP Developer Support Team (USA)

News

  • Please use the Blog Feedback? - Contact Us link at the top of the page to email questions relating to the blog itself.

    If you wish to ask a technical question, please use the links below to ask on the Newsgroups. If you ask on the Newsgroups, others in the community can respond and the answers are available for everyone in the future.

    Please do not use comments on pages and posts to ask questions unrelated to the topic on that page or post.



    Dates of Interest:

    11-Jul-2008: Blog Created by David Musgrave.
    10-Oct-2008: First Post by Scott Stephenson.
    04-Nov-2008: First Post by Dave Dusek.
    11-Nov-2008: First Post by Beth Gardner.
    28-Nov-2008: First Post by Chris Roehrich.
    30-Dec-2008: First Post by Patrick Roth.
    24-Feb-2009: First Post by Greg Willson.
    22-Apr-2009: First Post by David Clauson.
    04-May-2009: First Post by Ryan Wigestrand.
    19-Jun-2009: First Post by Dawn Langlie.
    03-Jul-2009: First Post by Emily Halvorson.
    23-Sep-2009: Created Twitter account with blog feed.



    WorldMaps Statistics since
    24-Feb-2009:




    Click for WorldMaps Stumbler



    Translator Tool:




    Social Networking

    Follow David Musgrave and the blog on:

    David Musgrave on Twitter

    David Musgrave on LinkedIn


    Disclaimer

    This blog is provided "AS IS" with no warranties, and confers no rights.

    The links in this blog may lead to third-party Web sites. Microsoft provides third-party resources to help you find customer service and/or technical support resources. Information at these sites may change without notice. Microsoft is not responsible for the content at any third-party Web sites and does not guarantee the accuracy of third-party information.

Contents

Favourite Posts

Blog Links

Newsgroups Links

Resources Links

spSearchOnAllDB: SQL Stored Procedure to Search an Entire Database

David MeegoFrom the Useful SQL Scripts Series.

This stored procedure allows you to search all columns in all tables in a database for the occurrence of a particular string or value.  Wild card characters such as those supported by the LIKE keyword can be used.

For example: _ to wild card a single character, and % to wild card a number of characters.

Once you have run the script to create the stored procedure you can execute it to look for data, here are some examples:

      exec  spSearchOnAllDB 'Sugar%'
      exec  spSearchOnAllDB '%soft%'
      exec  spSearchOnAllDB '_5234_57%', 1
      exec  spSearchOnAllDB M_cro_oft

This script is available from other locations around the Internet, but the one attached has had some minor changes to make it more suitable for working in a Dynamics GP environment, such as granting of access to DYNGRP.

Note: To include a single quote (') character in the search string, you will need to replace the single quote (') with 4 single quotes in a row ('''').  Doubling up a single quote will prevent the early termination of the search parameter and because the parameter is used in dynamically created scripts inside the stored procedure doubling up again allows the dynamic scripts to run correctly. 

The script is available as an attachment at the bottom of this post.

David

24-Jun-2009: Added hint about searching for single quotes.

Posted: Monday, December 01, 2008 11:30 AM by David Musgrave
Filed under: ,

Attachment(s): spSearchOnAllDB.zip

Comments

David Musgrave said:

# December 1, 2008 10:02 PM

Steve said:

Thanks!  Perfect timing!  I literally needed to do this today, and was wondering about how to do it.

# December 1, 2008 11:56 PM

US Microsoft Dynamics GP Field Team said:

Based on the success of the "Resolving Security Issues in Dynamics GP" located here, Microsoft Dynamics

# December 10, 2008 2:33 PM

Microsoft Dynamics GP US Field Team blog said:

Based on the success of the "Resolving Security Issues in Dynamics GP" located here, Microsoft

# December 10, 2008 9:05 PM

Hussain Al-Yousef said:

Thank you David, very good script.

Hussain Al-Yousef

hyou91@gmail.com

# February 25, 2009 3:51 AM

Leslie Vail said:

This is great!  I hope I can get it to work.

I ran the sp using the example

exec  spSearchOnAllDB 'Sugar%'

Results were returned from the Sugar% but then I also received this message:

Msg 102, Level 15, State 1, Line 1

Incorrect syntax near 'Name'.

What have I done wrong?

Leslie

# July 8, 2009 11:36 AM

Patrick Roth [MSFT] said:

Leslie,

I didn't have any issues on my TWO database or DYNAMICS db.  I'm wondering if you don't have a table with a column called "Name" in it as I don't see otherwise in the SQL how this couldn't work.

if you add right above the exec (sql) the line:

 print @sql

 exec(@sql)

Then on the Messages tab you'll see all the SQL statements being generated.  Search for "Name" in them and I suspect you'll see it is there and sql is unhappy about that because it probably is a reserved word.

We might need to add [] around the column and table fields in the SQL script.

# July 8, 2009 1:57 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker