Damien_The_Unbeliever noted that he was good only for numbers
Wade73 added decimal point bit
neizan did an additional setup, since he didnβt do this,
Unfortunately, none of them handle negative values, and they seem to have problems with a comma in the value ...
Here is my setting for getting negative values ββand commas
declare @MyTable table(MyVar nvarchar(10)); insert into @MyTable (MyVar) values (N'1234') , (N'000005') , (N'1,000') , (N'293.8457') , (N'x') , (N'+') , (N'293.8457.') , (N'......') , (N'.') , (N'-375.4') , (N'-00003') , (N'-2,000') , (N'3-3') , (N'3000-') ; -- This shows that Neizan answer allows "." to slip through. select * from ( select MyVar , case when MyVar not like N'%[^0-9.]%' then 1 else 0 end as IsNumber from @MyTable ) t order by IsNumber; -- Notice the addition of "and MyVar not like '.'". select * from ( select MyVar , case when MyVar not like N'%[^0-9.]%' and MyVar not like N'%.%.%' and MyVar not like '.' then 1 else 0 end as IsNumber from @MyTable ) t order by IsNumber; --Trying to tweak for negative values and the comma --Modified when comparison select * from ( select MyVar , case when MyVar not like N'%[^0-9.,-]%' and MyVar not like '.' and isnumeric(MyVar) = 1 then 1 else 0 end as IsNumber from @MyTable ) t order by IsNumber;
M McDonald Feb 09 '17 at 17:27 2017-02-09 17:27
source share