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 Parsing

Author  Topic 

sangeeta
Starting Member

16 Posts

Posted - 2007-02-08 : 16:08:24
Hi -

I am new to SQL server and was wondering if someone can help me with this one. Thanks
My table holds 2 columns (SECTOR and TERM) with following example values

SECTOR TERM
Hybrid 6/1 8
Hybrid 9/1 9
Hybrid 10/1 7
Hybrid 3/1 3

I would like to find out the rows where my values from SECTOR before '/' does not equal TERM

i.e.
Row 1 where 6<>8
and row 3 where 10<>7

Thanks.

X002548
Not Just a Number

15586 Posts

Posted - 2007-02-08 : 16:52:32
Does this

Hybrid 6/1

Belong in SECTOR?

What's the 1 for?



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

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

sangeeta
Starting Member

16 Posts

Posted - 2007-02-08 : 17:11:55
Brett -

Hybrid 6/1 is in Sector
and 8 is in term

1 is some value that I don't care about. I am trying to map 6 with 8

Thanks.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-09 : 01:04:15
[code]-- prepare sample data
declare @test table (sector varchar(20), term int)

insert @test
select 'Hybrid 6/1', 8 union all
select 'Hybrid 9/1', 9 union all
select 'Hybrid 10/1', 7 union all
select 'Hybrid 3/1', 3

-- Show the result
SELECT Sector
FROM @Test
WHERE CAST(Term AS VARCHAR) <> SUBSTRING(Sector, CHARINDEX(' ', Sector) + 1, CHARINDEX('/', Sector) - CHARINDEX(' ', Sector) - 1)[/code]

Peter Larsson
Helsingborg, Sweden
Go to Top of Page

sangeeta
Starting Member

16 Posts

Posted - 2007-02-09 : 10:31:39
Thanks a lot Peter.

I have never played with parsing features in sql. I should

Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-02-09 : 10:34:06
quote:
Originally posted by sangeeta

Thanks a lot Peter.

I have never played with parsing features in sql. I should





You should not unless you are out of options. These things can be better handled at Front-end.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -