[thelist] SQL Server: How Can I Convert VARCHAR to INT?

Ryan Finley RyanF at SonicFoundry.com
Thu Aug 16 15:04:37 CDT 2001


This is a much more elegant solution then using cursors!  I always forget
about that CASE statement.

	Ryan Finley
	President - SurveyMonkey.com

-----Original Message-----
From: Joshua Olson [mailto:joshua at alphashop.net] 
Sent: Thursday, August 16, 2001 3:04 PM
To: thelist at lists.evolt.org
Subject: Re: [thelist] SQL Server: How Can I Convert VARCHAR to INT?


Does something like this Work:

SELECT
  x =
  CASE
     WHEN IsNumeric(x) = '1' THEN Cast(x)
     ELSE NULL
   END
FROM mytable

This solution depends on the actual existance of an "IsNumeric" function and
a "Cast" function, as well as the database supporting the CASE-WHEN logic.

Did you actually want to update the table or just make a select that
returned what you wanted?

HTH,

-joshua


---------------------------------------
For unsubscribe and other options, including
the Tip Harvester and archive of TheList go to:
http://lists.evolt.org Workers of the Web, evolt ! 




More information about the thelist mailing list