How do select the first part of a string in Microsoft SQL

I have 10,000 SiteID records. All those beginning with "18" are closed records which I want to exclude. I have tried this but is doesn't work. Any ideas?

SELECT     SiteID, site_name, CustomerID
FROM         dbo.tblSite
WHERE     (LEFT(dbo.SiteID, 2) <> '18')
CMChalcraftFinance DirectorAsked:
Who is Participating?
 
Aneesh RetnakaranDatabase AdministratorCommented:
SELECT     SiteID, site_name, CustomerID
FROM         dbo.tblSite
where  siteid not like '18%'

or

SELECT     SiteID, site_name, CustomerID
FROM         dbo.tblSite
where  ltrim(siteid) not like '18%'
0
 
jb428jCommented:
I personally don't use "LIKE" if I don't have to.

WHERE SUBSTRING(SiteID,1,2) <> 18
0
 
CMChalcraftFinance DirectorAuthor Commented:
Excellent. That has worked. Thank you both for your help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.