sql server - Selecting positive numbers from char column -


i have table char column , want positive numbers it.

declare @tabela table (id varchar(20)) insert @tabela values ('-12'),('10'),('25'),('12a') 

i tried obvious queries like:

select * @tabela id > 0 , isnumeric(id) = 1 

and

select * (select * @tabela isnumeric(id) = 1) id  > 0 

and

;with (select * @tabela isnumeric(id) = 1) select * id  > 0 

but don´t work , returns error:

conversion failed when converting varchar value '12a' data type int

the following 1 worked, afraid not guaranteed work in situation, since can´t guarantee order of evaluation of clause:

select * @tabela isnumeric(id) = 1 , id  > 0 

and other option thought pretty ugly:

select * (     select case when isnumeric(id) = 1              case when id > 0                  id              end         end id     @tabela  ) id not null 

is there way positive numbers in 1 query?

try this:

select * table id not '%[^0-9]%' , id not '%-%' 

fiddle http://sqlfiddle.com/#!3/c769c/2


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Website Login Issue developed in magento -

Can the constants be defined inside a model file of a framework in PHP? -