April 22, 2010 at 10:08 am
I am trying to search multiple tables for numbers that contain a third decimal not equal to zero.
the columns are numeric.
For example...
if the column contains
34.0200
1232.0560
234.4400
451232.123
I want to list only records 1232.0560 and 451232.123
is that possible?
April 22, 2010 at 11:08 am
Check the charindex function to find the decimal and the substring function to get the third position after that. You'll need to convert the column to a varchar first.
April 22, 2010 at 11:51 am
declare @test-2 table (col1 numeric(10,4))
insert into @test-2
SELECT 34.0200 UNION ALL
SELECT 1232.0560 UNION ALL
SELECT 234.4400 UNION ALL
SELECT 451232.123
select * from @test-2
where col1 like '%.__[1-9]%'
This does do an implicit conversion of the field to a varchar, so it won't utilize an index. But it does get you what you wanted.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
April 22, 2010 at 3:30 pm
Very clever, Wayne. I like that.
Rob Schripsema
Propack, Inc.
April 22, 2010 at 3:43 pm
thanks everyone.. this one below worked best for me..
SELECT *
FROM [TSIT1].[dbo].[gl30000]
where
SUBSTRING(SUBSTRING(CAST(orcrdamt AS VARCHAR),CHARINDEX('.',CAST(orcrdamt AS VARCHAR))+1,LEN(CAST(orcrdamt AS VARCHAR))),3,1) <> '0'
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply