Re: How to tell if I can convert a varchar to int

From: Wayne Snyder (wsnyder_at_computeredservices.com)
Date: 03/10/04


Date: Wed, 10 Mar 2004 07:51:31 -0500

Maybe try datalength(column) which gives you the number of characters....

--
Wayne Snyder MCDBA, SQL Server MVP
Computer Education Services Corporation (CESC), Charlotte, NC
(Please respond only to the newsgroups.)
I support the Professional Association for SQL Server
(www.sqlpass.org)
"Chris Lacey" <chris.lacey@bigfoot.com> wrote in message
news:LnD3c.3274$re1.2931@newsfe1-win...
> Hi,
>
> I am attempting to write a procedure whereby I can get the maximum numeric
> value in a varchar column (which may contain a mix of words and number
> strings).
>
> I'm trying to use:
>
> SELECT MAX ( case isnumeric(value) when 1 then cast (value as int) else 0
> end ) FROM table
>
> However, given that entries in the value column can be up to 255
characters,
> I obviously have a problem when the number is too long to be cast as an
int
> (or indeed a bigint or whatever).
>
> In the case of this happening, I'd like to ignore these values, so what I
> need is a means of telling whether a value can be cast as an int before
> attempting to do it.  Using isnumeric(..) isn't enough because it can't
> confirm that I can actually convert it.
>
> Any help would be very welcome,
>
> Thanks in advance,
>
> Chris.
>
>


Relevant Pages

  • Re: How to tell if I can convert a varchar to int
    ... I support the Professional Association for SQL Server ... > value in a varchar column (which may contain a mix of words and number ... > need is a means of telling whether a value can be cast as an int before ...
    (microsoft.public.sqlserver.server)
  • How to tell if I can convert a varchar to int
    ... I am attempting to write a procedure whereby I can get the maximum numeric ... value in a varchar column (which may contain a mix of words and number ... I obviously have a problem when the number is too long to be cast as an int ...
    (microsoft.public.sqlserver.programming)
  • How to tell if I can convert a varchar to int
    ... I am attempting to write a procedure whereby I can get the maximum numeric ... value in a varchar column (which may contain a mix of words and number ... I obviously have a problem when the number is too long to be cast as an int ...
    (microsoft.public.sqlserver.server)
  • Re: WHERE clause applies to right-hand table of LEFT JOIN
    ... it's always best to specify INNER JOIN ... T1_PK int NOT NULL ... CONSTRAINT FK_T2_T1 FOREIGN KEY ... The SQL Server cost-based optimizer is very good at generating efficient ...
    (microsoft.public.sqlserver.server)
  • Re: WHERE clause applies to right-hand table of LEFT JOIN
    ... it's always best to specify INNER JOIN ... T1_PK int NOT NULL ... CONSTRAINT FK_T2_T1 FOREIGN KEY ... The SQL Server cost-based optimizer is very good at generating efficient ...
    (microsoft.public.access.queries)