Click to See Complete Forum and Search --> : <=


vin
August 31st, 2000, 08:57 AM
I have a little problem using sql server.

Suppose I have a field of char(10)

i want to get all records that the first letters
are between say 'a' and 'f'
for example

'aasdf'
'bbdfs'
'cerwt'
'ddfsd'
'ferer'

so I write the following

select * from mytable where myfield = "a"

however this never gets any record beginnig
with "f".

Can anyone tell me why?



Valery Iskarov Nikolov
http://listen.to/quark

Johnny101
August 31st, 2000, 03:18 PM
try using this as your query:

sql = "SELECT * FROM myTable "
sql = sql & "WHERE substring(myField,1,1) = 'f'"




substring is a SQL Server command, its like the MID function in VB - this approad seems to work much better for doing string criteria.

hope this helps,

john

John Pirkey
MCSD
http://www.ShallowWaterSystems.com
http://www.stlvbug.org

Johnny101
August 31st, 2000, 03:21 PM
oops, hehehe forgot the second part...

sql = "SELECT * FROM MyTable "
sql = sql & "WHERE substring(MyField,1,1) => 'a' AND substring(MyField,1,1) <= 'f'" '




this should do it for you.

sorry about the first (incomplete) post.

John

John Pirkey
MCSD
http://www.ShallowWaterSystems.com
http://www.stlvbug.org

vin
September 1st, 2000, 03:18 AM
Hi

Even the first post was more than enough :)

Thank you very much!



Valery Iskarov Nikolov
http://listen.to/quark

zero1143
September 7th, 2000, 08:41 AM
try something like:
select * from employee where fname like 'P%'

zero1143
September 7th, 2000, 08:45 AM
you might also try:
select * from employee where fname like 'P%'

jim enright
October 6th, 2000, 04:47 PM
select
*
from
mytable
where
myfield = "a"

you are saying that the above does not work? you might want to try avoiding single quotes:

select
*
from
mytable
where
myfield = "a"