Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Simple Query - what's wrong?

Author  Topic 

mikebird
Aged Yak Warrior

529 Posts

Posted - 2009-05-29 : 09:27:19
select distinct
substring(det_analysis, 8, 3)
from sl_pl_nl_detail
where substring(det_analysis, 8, 3) not in (select distinct cuuser2 from sl_accounts)


the 2nd line
give a list of 61 codes

The subquery in the where clause is a subset of 14 of those codes. I just want a list of those 61 codes which are not one of those 14. When I run this, there are no results. I bet you can tell me what I've done wrong. Looks fine to me. Putting the two columns side-by-side I can see what I want to get

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-05-29 : 10:06:54
Maybe that:

select distinct
substring(det_analysis, 8, 3)
from sl_pl_nl_detail
where substring(det_analysis, 8, 3) not in (select distinct ltrim(rtrim(cuuser2)) from sl_accounts)



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

mikebird
Aged Yak Warrior

529 Posts

Posted - 2009-05-29 : 10:28:21
Well, it's impossible to tell if that reply was meant to be helpful or as a well-known joke to make in any situation, as the query is still running that, even now!!

I got frustrated with that simple syntax, always where a DB is supposed to be perfect and take care of long-winded tasks. I typed in that list of items myself and got just what I needed very quickly.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-05-29 : 10:41:42
I did not get you.
My english is not perfect.
Do you think that I meant my reply as a joke?
I meant it to be helpful because often there are not visible spaces in some column so a compare will fail



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -