Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Select from begining of string

Author  Topic 

mdwan
Starting Member

1 Post

Posted - 2003-03-26 : 12:10:51
Hello. I need to select rows based on several characters at the begining of a column. However, when i use "where colname like whatever%" it grabs rows that match the characters even though they occur somewhere in the middle of the string. Any suggestions on how to only match at the begining of a string? Thanks!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-03-26 : 12:23:45
SELECT * FROM Table1
WHERE column1 LIKE 'whatever%'

The above code should only return records that start with whatever. It should not return ones that have whatever in the middle of the string. Are you putting a % before whatever (%whatever%)?

Tara
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2003-03-26 : 13:04:26
Tara's correct. Can you post you're actual query.

Here's a sample that shows the difference.

USE Northwind
GO

SELECT * FROM Products WHERE ProductName Like 'A%'
GO

SELECT * FROM Products WHERE ProductName Like '%Hot%'
GO


Brett

8-)
Go to Top of Page
   

- Advertisement -