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
 Select Query

Author  Topic 

empyrean
Starting Member

14 Posts

Posted - 2009-09-30 : 10:32:50
Hi

I wanted to select the coulumns based on this statement.

I have data like

ZD0892837d39934.123 D DAVID.PD
ZD0938383D32484.324 D DAVID.AD
ZF0844838F32933.234 D DAVID.AD

now i wanted to selet the rows by checking this condition. If second letter in first column(ZD0892837d39934.123) is equal to first letter in second column (D DAVID.PD) then these rows are to be excluded and based on this condition i need to display only third row.

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2009-09-30 : 10:34:57
SELECT stuff
from table
where substring(col1,2,1) <> left(col2,1)

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-30 : 10:39:28

select columns from your_table
where substring(col1,2,1) <>left(col2,1)

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-30 : 10:39:58


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

empyrean
Starting Member

14 Posts

Posted - 2009-09-30 : 10:46:11
Thank you so much. it worked :)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-30 : 10:59:46
Another method

select columns from your_table
where col2 not like substring(col1,2,1)+'%'

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -