Re: How to tell if I can convert a varchar to int
From: Wayne Snyder (wsnyder_at_computeredservices.com)
Date: 03/10/04
- Next message: Hari: "Re: Alias"
- Previous message: Dennis Hancy: "Re: Wildcards in REPLACE function?"
- In reply to: Chris Lacey: "How to tell if I can convert a varchar to int"
- Next in thread: Dan Guzman: "Re: How to tell if I can convert a varchar to int"
- Messages sorted by: [ date ] [ thread ]
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. > >
- Next message: Hari: "Re: Alias"
- Previous message: Dennis Hancy: "Re: Wildcards in REPLACE function?"
- In reply to: Chris Lacey: "How to tell if I can convert a varchar to int"
- Next in thread: Dan Guzman: "Re: How to tell if I can convert a varchar to int"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|