Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update Query only for rows "begins with"?

Status
Not open for further replies.

nstouffer

Programmer
Jan 11, 2002
52
US
In SQL Command is it possible to do this?

Update compcode
Set Seg1 = '28'
Where Company (begins with 'R')???

In VBA, I would say:

Where Left(Company, 1) = 'R'

thanks in advance
 
Two ways:

Update compcode
Set Seg1 = '28'
Where SUBSTRING(Company,1,1) = 'R'

or

Update compcode
Set Seg1 = '28'
Where Company LIKE 'R%'

 
P.S.
If company is indexed, then the LIKE approach might be better than the SUBSTRING. Something tells me that SQL might be more likely to use the index with LIKE, but in fact they might perform exactly the same.
 
This is how you do this with SQL commands

update compcode set Seg1='28' where Company like 'R%'
 
You can issue exactly the command you would for VB, using the 'Left' operator. Your command works fine.

Select * from
where Left(Company, 1) = 'R'

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top