Are you sure the fields in your database all start do not start with a space?
You could also use
WHERE LEFT(SSN,2) == "45"
Main Topics
Browse All TopicsJust when I think I understand!
Example 1:
I'm searching by SS#. They're stored as Char in the table. Regardless of the setting of SET EXACT, when my condition reads: WHERE TRIM(ssnum) = "45", the SQL Select pulls records containing no SS# as well as those starting with 45. When I remove the TRIM(), it only pulls the latter (as I want).
(I took all joins out of my SQL Select to ensure it wasn't muddling the issue.)
I don't get why "" = "45" is pulling the blank records. I have studied the chart at http://msdn.microsoft.com/
Example 2:
For reasons unimportant, I'm trying to offer the ability to enter a few numbers of the account number (which is the PK) and have all account numbers returned that begin with the criteria. Using TRIM(TRANSFORM(user.acctnu
Will someone enlighten me?
Thank you.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Whil ANSI is the setting for SQL, I can't reproduce what you're saying, that you get records without any SSN if you filter ssn='45'. Only Set Ansi Off in combination with where SSN='4' results in all SSN starting with 4, not only 4. Ansi On makes it work like expected.
If you want 'normal' behavior, SET ANSI ON, and for matching a condition "begins with 4" use LIKE '4%'
Bye, Olaf.
When you say.. "pulls records containing no SS# "
Are those bad record values NULL or Empty?
I have seen situations where a NULL record value is returned on a query when it was not wanted, but, like Olaf has confirmed above, Blank records were not.
One way to eliminate NULL records would be to use an additional WHERE parameter (or two)
WHERE <normal criteria>;
AND NOT NULL(ssn);
AND NOT EMPTY(ssn)
Alternatively you could use the SET NULL ON/OFF environment parameter or the NVL() function.
Good Luck
Business Accounts
Answer for Membership
by: tusharkanvindePosted on 2009-07-03 at 21:48:53ID: 24775744
SQL SELECT does not check the value of SET EXACT ON/OFF. Instead it checks the value of SET ANSI ON/OFF