Home All Groups Group Topic Archive Search About

using LIKE to query the leftmost character

Author
12 May 2005 11:58 PM
.Net Sports
in an sql statement that is concatenating asp, i want to query first
names to a customer database with LIKE:

"SELECT fname + ' ' + fname AS Name, cust_id " _
                & "FROM tblcusttag " _
        & "WHERE fname LIKE '%" & Left(strSearch,1)

...having trouble usingLeft function, as when the user does the query,
they have to correctly have the first letter of the first name right in
the customer query. strSearch is the ID of the textbox that they enter
the text in.

TIA
..netSports

Author
13 May 2005 12:05 AM
Tom Moreau
You should really use a stored proc.  Send across only the first character
of the test string:

create proc MyProc
(
    @char char (1)
)
as
set nocount on

select
    fname + ' ' + lname as Name
,    cust_id
from
    tbl_custtag
where
    fname like @char + '%'
go

--
   Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON   Canada
www.pinpub.com
..
".Net Sports" <ballz2w***@cox.net> wrote in message
news:1115942330.931843.190930@o13g2000cwo.googlegroups.com...
in an sql statement that is concatenating asp, i want to query first
names to a customer database with LIKE:

"SELECT fname + ' ' + fname AS Name, cust_id " _
& "FROM tblcusttag " _
& "WHERE fname LIKE '%" & Left(strSearch,1)

...having trouble usingLeft function, as when the user does the query,
they have to correctly have the first letter of the first name right in
the customer query. strSearch is the ID of the textbox that they enter
the text in.

TIA
..netSports

AddThis Social Bookmark Button