Avatar of Sandra Smith
Sandra Smith
Flag for United States of America asked on

SELECT statement not returning data

Ok, it has been a while since I worked on an actual server database, I have been mostly wokring in ACCESS.  So, I have the below query that simply refuses to work.  There is data in the table, but I do not know what is wrong with my select statement.  I want all the loans except those that have 10 digits in the number and no text characters.  what is going on is the nubmer i want are in the form like 11111.10 or 11111-10, but NOT accounts 000000002 or 11111-10C.
SELECT balview.LOAN, balview.PRIN_BAL_P, balview.PRIN_BAL_P
	FROM balview
	WHERE balview.LOAN Like '?????.*' Or balview.LOAN Like '?????-*' 
		   And balview.LOAN Not Like '*[A-Z]*') 
		AND balview.ACCOUNTING_DATE = '2007-11-30'

Open in new window

Microsoft SQL Server 2005Microsoft DevelopmentSQL

Avatar of undefined
Last Comment
Sandra Smith

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Aneesh

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Guy Hengel [angelIII / a3]

let's see:
* you placed a ) but I don't see the ( for that one
* you have a OR, but to get this working properly, you need a () around the 2 OR parts.
* I replaced the NOT LIKE by a LIKE with a changed pattern
SELECT balview.LOAN, balview.PRIN_BAL_P, balview.PRIN_BAL_P
      FROM balview
      WHERE ( balview.LOAN Like '?????.*' Or balview.LOAN Like '?????-*'  )
               And balview.LOAN Like '*[^A-Z]*'
            AND balview.ACCOUNTING_DATE = '2007-11-30'

Open in new window

Guy Hengel [angelIII / a3]

and yes, with sql server it is _ and not ?

SELECT balview.LOAN, balview.PRIN_BAL_P, balview.PRIN_BAL_P
      FROM balview
      WHERE ( balview.LOAN Like '?????.*' Or balview.LOAN Like '?????-*'  )
               And balview.LOAN Like '*[^A-Z]*'
            AND balview.ACCOUNTING_DATE = '2007-11-30'

Open in new window

Sandra Smith

ASKER
Actually, in the code I did correct that, but still did not work.  aneeshattingal, will try your version.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Sandra Smith

ASKER
Aneeshattingal, thankyou, got it to work, but I don't understand the difference between the ? character and the _?  Are not both placeholders for one character?
Aneesh

yes, _ stands for a single character in sql
Sandra Smith

ASKER
Thank you both.  Switching is going to be a struggle for the next few weeks, so expect more questions.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.