Solved

show records that have character string grater than 2

Posted on 2010-11-30
3
195 Views
Last Modified: 2012-05-10
I have a query that displays customer information, I want to display the records where the state is grater than 2 characters
SELECT     TOP (100) PERCENT CUSTNMBR, CUSTNAME, ADDRESS1, ADDRESS2, CITY, STATE, ZIP, PHONE1

FROM         dbo.RM00101

WHERE     (NOT (ADDRESS1 = ADDRESS2)) AND (NOT (CUSTCLAS = 'OBS')) AND (NOT (CUSTCLAS = 'EMP')) AND (NOT (CUSTCLAS = 'EXP')) AND 

                      (NOT (CUSTCLAS = 'ADV')) AND (NOT (CUSTCLAS = '')) AND (NOT (CUSTCLAS = 'VEN')) AND (NOT (CUSTNMBR LIKE '%MISC%')) AND 

                      (ADRSCODE = 'PRIMARY') AND (NOT (ZIP = ' ')) AND (NOT (ZIP LIKE '%N%')) AND (NOT (ZIP = '14624')) AND (NOT (STATE = ' ')) AND (NOT (STATE = '67')) 

                      AND (NOT (ADDRESS1 = '100 airpark drive')) AND (NOT (ADDRESS1 LIKE '%PAYABLE%')) AND (NOT (ADDRESS1 LIKE 'Business%')) AND 

                      (NOT (ADDRESS1 LIKE 'Attn%')) AND (NOT (CUSTCLAS LIKE 'CF')) AND (NOT (CUSTCLAS LIKE 'FA')) AND (NOT (CUSTCLAS LIKE 'PD')) AND 

                      (NOT (CUSTCLAS LIKE 'SA')) AND (NOT (CUSTCLAS LIKE 'SD')) AND (NOT (CUSTCLAS LIKE '.')) AND (NOT (CUSTCLAS LIKE 'PA')) AND 

                      (NOT (CUSTCLAS LIKE 'DNS')) AND (NOT (CUSTCLAS LIKE 'NC')) AND (NOT (HOLD = 1)) AND (NOT (INACTIVE = 1)) AND (NOT (CITY = ' '))

ORDER BY CUSTCLAS

Open in new window

0
Comment
Question by:skull52
3 Comments
 
LVL 1

Assisted Solution

by:pjpatricio
pjpatricio earned 200 total points
Comment Utility
Just add AND LEN(STATE)>2 to your where clause
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 300 total points
Comment Utility
Or if you want to ignore spaces:

LEN(RTRIM(LTRIM(STATE)))>2
0
 

Author Comment

by:skull52
Comment Utility
Thanks, Both worked but Erick's gave the best result because it ignored the spaces.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now