Solved

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

Posted on 2010-11-17
3
250 Views
Last Modified: 2012-05-10
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')
0
Comment
Question by:CMChalcraft
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 250 total points
ID: 34156510
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
 
LVL 1

Assisted Solution

by:jb428j
jb428j earned 250 total points
ID: 34157759
I personally don't use "LIKE" if I don't have to.

WHERE SUBSTRING(SiteID,1,2) <> 18
0
 

Author Comment

by:CMChalcraft
ID: 34163675
Excellent. That has worked. Thank you both for your help.
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question