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.
| Author |
Topic |
|
kieran5405
Yak Posting Veteran
96 Posts |
Posted - 2009-09-16 : 05:46:09
|
| Hi,I have a 'float' column in my sql db called Number_Days. The column can be in whole number format i.e. 1.0, 5.0, 8.0 etc... or else in half days formats i.e. 2.5, 1.5, 8.5 etc..I now need to return only the values which have a half day format i.e. 2.5. Any idea how i can do this.Thanks for any help... |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-09-16 : 05:56:14
|
SELECT Number_Days FROM [YOURTABLE] WHERE Number_Days LIKE '%.5' Hope can help...but advise to wait pros with confirmation... |
 |
|
|
kieran5405
Yak Posting Veteran
96 Posts |
Posted - 2009-09-16 : 06:00:21
|
quote: Originally posted by waterduck SELECT Number_Days FROM [YOURTABLE] WHERE Number_Days LIKE '%.5' Hope can help...but advise to wait pros with confirmation...
of course!!! how did i miss that!! thanks!!! |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-09-16 : 06:02:40
|
That needs to do a convert to varchar first, because you cannot use like and '%' on numeric datatype SELECT Number_Days FROM [YOURTABLE] WHERE convert(varchar(10),Number_Days) LIKE '%.5' No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-09-16 : 06:35:47
|
| orceiling(Number_Days)<>floor(Number_Days)MadhivananFailing to plan is Planning to fail |
 |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-09-16 : 06:39:29
|
[code]DECLARE @fun TABLE(col1 float)INSERT INTO @fun SELECT2.5 UNION SELECT3.5 UNION SELECT4.5 UNION SELECT6.5 UNION SELECT1.0 UNION SELECT2 UNION SELECT6 UNION SELECT8 UNION SELECT4 UNION SELECT5SELECT * FROM @fun where col1 LIKE '%.5'[/code]works? Hope can help...but advise to wait pros with confirmation... |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-09-16 : 06:47:26
|
OK! It works but I think there happens an implicit convert. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|