|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Simple SELECT statement???Can someone please tell me how I do a select for values that starts with a
letter... For example if I wanted to find all the employees from a database that lastnames started with "A"??? EG... SQL = "SELECT LastName, FirstName, Initial,Dept,TeleNo, Email FROM tblNonADUsers WHERE lastname =" & alpha & "* ORDER BY LastName ASC" Thanks for any help! SQL = "SELECT LastName, FirstName, Initial,Dept,TeleNo, Email FROM
tblNonADUsers WHERE lastname LIKE" & alpha & "% ORDER BY LastName ASC" Show quote "Tim::.." <myatix_at_hotmail.com> wrote in message news:F4FB7A55-1C70-4D31-8843-D1BE9E41A1EA@microsoft.com... > Can someone please tell me how I do a select for values that starts with a > letter... > > For example if I wanted to find all the employees from a database that > lastnames started with "A"??? > > EG... > SQL = "SELECT LastName, FirstName, Initial,Dept,TeleNo, Email FROM > tblNonADUsers WHERE lastname =" & alpha & "* ORDER BY LastName ASC" > > Thanks for any help! In news:O$EhDs4kFHA.320@TK2MSFTNGP09.phx.gbl, Roji. P. Thomas <thomasr***@gmail.com> said:> SQL = "SELECT LastName, FirstName, Initial,Dept,TeleNo, Email FROM Close, but no banana.> tblNonADUsers WHERE lastname LIKE" & alpha & "% ORDER BY LastName > ASC" SQL = "SELECT LastName, FirstName, Initial,Dept,TeleNo, Email FROM tblNonADUsers WHERE lastname LIKE '" & alpha & "%' ORDER BY LastName ASC" -- Steve Use a string function like RIGHT,lEFT or SUBSTRING
Select * from Customers where LEFT(lastname,1) = 'A' HTH, Jens Suessmeyer. Show quote "Tim::.." wrote: > Can someone please tell me how I do a select for values that starts with a > letter... > > For example if I wanted to find all the employees from a database that > lastnames started with "A"??? > > EG... > SQL = "SELECT LastName, FirstName, Initial,Dept,TeleNo, Email FROM > tblNonADUsers WHERE lastname =" & alpha & "* ORDER BY LastName ASC" > > Thanks for any help! In news:6B9D26A1-42F9-44CA-ABC6-1D54CD45ED41@microsoft.com, Jens Süßmeyer <JensSme***@discussions.microsoft.com> said:> Use a string function like RIGHT,lEFT or SUBSTRING It would be a bad idea to do this, as SQL Server would have to do a scan to> > Select * from Customers where LEFT(lastname,1) = 'A' > > HTH, Jens Suessmeyer. find matching records. Use "like" to find strings beginning with certain characters, as it can then use a seek. -- Steve (a) SQL Server uses % not * for wildcards
(b) wildcard searches require LIKE, not =, since the value will NOT be equal to the string you present (c) strings need to be enclosed in single quotes ' ' SQL = "SELECT ... WHERE LastMame LIKE '" & alpha & "%' ORDER BY ..." Show quote "Tim::.." <myatix_at_hotmail.com> wrote in message news:F4FB7A55-1C70-4D31-8843-D1BE9E41A1EA@microsoft.com... > Can someone please tell me how I do a select for values that starts with a > letter... > > For example if I wanted to find all the employees from a database that > lastnames started with "A"??? > > EG... > SQL = "SELECT LastName, FirstName, Initial,Dept,TeleNo, Email FROM > tblNonADUsers WHERE lastname =" & alpha & "* ORDER BY LastName ASC" > > Thanks for any help! Hi
LIKE is what you want. SQL = "SELECT LastName, FirstName, Initial,Dept,TeleNo, Email FROM tblNonADUsers WHERE lastname LIKE '" & alpha & "%' ORDER BY LastName ASC" Regards -------------------------------- Mike Epprecht, Microsoft SQL Server MVP Zurich, Switzerland MVP Program: http://www.microsoft.com/mvp Blog: http://www.msmvps.com/epprecht/ Show quote "Tim::.." wrote: > Can someone please tell me how I do a select for values that starts with a > letter... > > For example if I wanted to find all the employees from a database that > lastnames started with "A"??? > > EG... > SQL = "SELECT LastName, FirstName, Initial,Dept,TeleNo, Email FROM > tblNonADUsers WHERE lastname =" & alpha & "* ORDER BY LastName ASC" > > Thanks for any help! Don't worry...
Show quote "Tim::.." wrote: > Can someone please tell me how I do a select for values that starts with a > letter... > > For example if I wanted to find all the employees from a database that > lastnames started with "A"??? > > EG... > SQL = "SELECT LastName, FirstName, Initial,Dept,TeleNo, Email FROM > tblNonADUsers WHERE lastname =" & alpha & "* ORDER BY LastName ASC" > > Thanks for any help! |
|||||||||||||||||||||||