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
 I want to add a condition in my selection

Author  Topic 

goligol
Posting Yak Master

128 Posts

Posted - 2011-06-29 : 17:52:26
In my query from table [cf07ur00].[comm], I want to find the comm where their length is not 4 and also if their length is 3, their first digit in right is not 0.

Out of the table
comm
01
010
0100
02
021
0210
022

I want to have:
CC
01
02
021
022

SELECT [comm] CC
FROM [bts].[cf07ur00].[comm]
where LEN(comm) <> 4
and RIGHT (comm,1)!= 0 when len(comm) = 3

singularity
Posting Yak Master

153 Posts

Posted - 2011-06-29 : 19:16:04
[code]
SELECT [comm] CC
FROM [bts].[cf07ur00].[comm]
where LEN(comm) <> 4 and not (RIGHT(comm,1) = 0 and len(comm) = 3)
[/code]
Go to Top of Page

goligol
Posting Yak Master

128 Posts

Posted - 2011-06-30 : 12:13:13
Thank you
Go to Top of Page
   

- Advertisement -