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 2008 Forums
 Transact-SQL (2008)
 SQL select where number is less than

Author  Topic 

crazyco
Starting Member

30 Posts

Posted - 2012-01-18 : 09:57:34
Can someone help. I have a table with an outcome column of:

4.8.1
6.4.1.1
6.4.1.1
5.1.7
5.1.7
23.35.4.5

How do I select those numbers which are less than 6.1?

Thanks

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2012-01-18 : 10:11:00
Hello crazyco,

Perhaps something like this would stimulate some thought?

SELECT 
[output],p
FROM
(
SELECT [output], CAST(PARSENAME(REVERSE(output),1) + '.' + PARSENAME(REVERSE(output),2) AS NUMERIC(10,2)) AS p
FROM @table
) d
WHERE d.p < 6.1


HTH.
Go to Top of Page

crazyco
Starting Member

30 Posts

Posted - 2012-01-18 : 10:17:20
Thank you, it turns out I misinterpreted the question anyway so this wasn't even required, but thank you anyway as its good for me to keep note of these things.
Go to Top of Page

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2012-01-18 : 10:18:27
yvw.

Have a nice day.
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2012-01-18 : 11:05:48
damn!

DECLARE @foo TABLE (
[val] VARCHAR(20)
)
INSERT @foo ([val])
VALUES ('4.8.1')
, ('6.4.1.1')
, ('6.4.1.1')
, ('5.1.7')
, ('5.1.7')
, ('23.35.4.5')
, ('6.11')
, ('6')
, ('6.1')
, ('FOOBARRED')

SELECT *, CHARINDEX('.', [val], 0) FROM @foo

SELECT * FROM @foo
WHERE
[val] < '6.100000001'
AND CHARINDEX('.', [val], 0) <= 2


Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page
   

- Advertisement -