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
 General SQL Server Forums
 New to SQL Server Programming
 help with like...

Author  Topic 

JJ297
Aged Yak Warrior

940 Posts

Posted - 2010-10-06 : 15:27:26
I'm trying to get all of the records except the one's that start with the letter R. I can't get this to work...

SELECT COSSN, MVT_TYP, MVT_CDT, MVT_LOC, MVT_DEST
FROM T16pendmvt
WHERE MVT_LOC not like 'r%';

The MVT_LOC field is a char(3) field and some of the data is:
R48
R46
R42

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-06 : 15:30:18
What you posted does work. Here is my quick test:

declare @t table (test char(3))

insert into @t values ('r48')
insert into @t values ('tuh')

select * from @t where test not like 'r%'


Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2010-10-06 : 15:33:56
Okay thanks I don't know why it's not working on my Database. Okay let me investigate more.
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2010-10-06 : 15:57:50
quote:
Originally posted by JJ297

I'm trying to get all of the records except the one's that start with the letter R. I can't get this to work...

SELECT COSSN, MVT_TYP, MVT_CDT, MVT_LOC, MVT_DEST
FROM T16pendmvt
WHERE MVT_LOC not like 'r%';

The MVT_LOC field is a char(3) field and some of the data is:
R48
R46
R42


Is it possible that your collation is case sensitive?

Be One with the Optimizer
TG
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-10-06 : 15:59:26
Is your database set up as cas sensitive?

I hate when that happens



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx





Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-06 : 16:01:16
Oh yes, good call!

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-06 : 16:01:40
JJ297, run this to see if that's the issue:

SELECT COSSN, MVT_TYP, MVT_CDT, MVT_LOC, MVT_DEST
FROM T16pendmvt
WHERE MVT_LOC not like 'R%';

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2010-10-08 : 10:43:38
Thanks all for getting back to me. I'm thinking it's not working because I need to set up a subquery and I was trying to set each one up by it self then tie all together. Here's my attempt at this but didn't get too far. Could you assist me please:

Select Count(Cossn) as Cossn
from t16pendall a
where (MFT_POSN1_CD = 'b' or MFT_POSN1_CD='d')
or (MFT_POSN1_CD = 'a' and Aged_Alien_RSW='Y') a
join t16pendmvt b on a.cossn=b.cossn
where b.cossn not in t16pendmvt

This is what I want...

Count (COSSN), MFT_POSN1_CD = B or D or (MFT_POSN1_CD = A and AGED_ALIEN_RSW = Y) and COSSN is not = COSSN in T16pendmvt, and (2) T16pendmvt table - Count (COSSN), (MVT_TYP = R and MVT_LOC not = R** or S** or V**), and (3) T16pendmvt table - Count (COSSN) and MVT_TYP = T
Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2010-10-08 : 10:51:06
Let me rewrite the query that I want...

To get the Pending Count of COSSN I need to add the following...

1) Use T16pendall table to Count (COSSN), MFT_POSN1_CD = B or D or (MFT_POSN1_CD = A and AGED_ALIEN_RSW = Y) and COSSN is not = COSSN in T16pendmvt, and

(2) use T16pendmvt table to Count (COSSN), (MVT_TYP = R and MVT_LOC not = R** or S** or V**), and

(3) use T16pendmvt table to Count (COSSN) and MVT_TYP = T
Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2010-10-08 : 11:06:43
okay got a bit farther. I broke them all up but don't know how to fix the top query and how to place them all together. Help please...

select count(cossn) as cossn
from t16pendall a
join t16pendmvt b on a.cossn = b.cossn
where (MFT_POSN1_CD = 'b' or MFT_POSN1_CD='d')
or (MFT_POSN1_CD = 'a' and Aged_Alien_RSW='Y') and
Cossn not in the t16pendmvt table
(don't know how to write this)

select count(cossn) as cossn
from t16pendmvt
where Mvt_typ ='r' and mvt_loc <> 'r%' or mvt_loc='s%' or mvt_loc='v%'

select count(cossn) as cossn
from t16pendmvt
where MVT_Typ ='t'
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-08 : 13:27:20
I'm confused how we jumped from a simple LIKE query to all of this. Did you confirm that you aren't using case sensitive collation?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2010-10-08 : 14:52:30
Yes I did confirm and it doesn't matter but I got this to work:

select count(cossn) as cossn
from t16pendmvt
where Mvt_typ ='r' and mvt_loc <> 'r%' or mvt_loc='s%' or mvt_loc='v%'


I have another question and will open another post. Thanks.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-08 : 14:59:40
Your query should not work as it isn't using LIKE/NOT LIKE.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2010-10-08 : 15:10:09
Sorry I put the wrong one down:

select count(cossn) as cossn
from t16pendmvt
where mvt_typ='r'and (mvt_loc like' R%' or mvt_loc like' S%')

This one works!
Go to Top of Page
   

- Advertisement -