[dba-SQLServer] SQL WildCard Searches

Robert L. Stewart rl_stewart at highstream.net
Wed Jul 26 16:05:12 CDT 2006


Declare a forward-only cursor to get the list of words.
Get the first value.
Run the select below.
fetch the next row.
Loop to run the select again.

Do this until the end of the cursor.

A cursor operates similar to a recordset in Access.

Doing that, you would want to store the results somewhere so you 
could know what they were.  So instead of a select, you might want an 
insert into based on the select.



At 12:00 PM 7/26/2006, you wrote:
>Date: Wed, 26 Jul 2006 16:03:13 +0000
>From: "Mark A Matte" <markamatte at hotmail.com>
>Subject: Re: [dba-SQLServer] SQL WildCard Searches
>To: dba-sqlserver at databaseadvisors.com
>Message-ID: <BAY121-F393399399B84A19F0EF8F4D25B0 at phx.gbl>
>Content-Type: text/plain; format=flowed
>
>Thanks Again Robert,
>
>Is there a way to call this procedure from within SQL Server...I'm trying to
>do this all in SQL Server and not involve Access.  I can call the sproc from
>the query analyzer...but I can only pass a single value.  How can I, using
>the logic below(all where clauses in table),from the query analyzer...loop
>through the records in my criteria table and execute the sproc on each one?
>
>Thanks,
>
>Mark A. Matte
>
>
> >From: "Robert L. Stewart" <rl_stewart at highstream.net>
> >Reply-To: dba-sqlserver at databaseadvisors.com
> >To: dba-sqlserver at databaseadvisors.com
> >CC: markamatte at hotmail.com
> >Subject: Re: [dba-SQLServer] SQL WildCard Searches
> >Date: Mon, 24 Jul 2006 13:02:03 -0500
> >
> >Mark,
> >
> >A stored procedure for each field you want to search.
> >
> >Something similar to this:
> >
> >CREATE PROCEDURE uspSearchField1
> >      @Word varchar(20)
> >AS
> >SELECT *
> >FROM MyTable
> >WHERE TheField LIKE '%' + @word + '%'
> >





More information about the dba-SQLServer mailing list