How to SELECT only '123' and exclude 'ABC' ?

  • Dear,

    If a table with a VARCHAR or NVARCHAR column, its values can be either characters or numbers, now, I want to write a SELECT statement which will only extract those records have '123', '234', ........... only.

    How can I write it ?

  • Do you mean something like this:

    select * from myTable where myColumn in ('123','234','345')

    Matt.

  • The column's data type is VARCHAR or NVARCHAR, it is assumed that user will only input numeric data, eg. 123, 3, 4, 32.

    However, due to some human mistakes, some users have entered some non-numeric data, eg. 'ABC', 'cde', ....

    Now, I want to SUM(the column) up but I have to exclude those 'ABC', 'cde',

    How can I do that ?

  • Hi

    Use the isnumeric function.

    ex: select sum(cast(col1 as int)) from table1 where isnumeric(col1) = 1.

    "Keep Trying"

  • Ahh, apologies. Chriag's solution would work nicely.

    Matt.

  • Thanks every bodies.

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply