Wrox Programmer Forums
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 14th, 2003, 12:40 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default VAL equivilent

1. What is the equivilent of Access's VAL in SQL?

Example: "EQ12345" becomes 12345 (and is a number)

2. Also, is there a different/better way of converting the string "98765" to 98765 (a number)?

Thanks!
__________________
Mitch
 
Old October 15th, 2003, 06:42 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

1. There isn't one. (P.S. I didn't think 'val()' would convert 'EQ12345' as you indicate. I thought it stopped as soon as it encountered a nonnumeric character, which would be the first one). In any case, I don't know a good way to do what you want, except to parse off the string one character at a time and build another with just the numeric characters via LIKE, then convert the string to numeric. This is, of course, procedural and ugly in SQL.

2. To convert the string '98765' to an integer, use CAST, eg. CAST('98765' as integer)

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
 
Old October 15th, 2003, 10:50 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Bingo! :)

I was actually using: Val(Mid([OrigID],3)) which returned a string version of the number then VAL converted it to an actual number. I glossed over what the code was actually doing.

Now I remember that VAL dosen't strip out the letters. (Althought, that would be neet function.)

I actually was using CAST elswhere so I kind of know how to use it.

Thanks!





Similar Threads
Thread Thread Starter Forum Replies Last Post
.NET Equivilent to ItemData(NewIndex) = ??? VBM2 Visual Basic 2005 Basics 1 February 19th, 2007 08:14 AM
How to add parameter val containing single quote prog ADO.NET 3 May 24th, 2005 09:24 AM
By Val By Ref B.V.Madhav Crystal Reports 1 May 12th, 2005 11:37 PM
SQL Query - VAL Function itHighway Classic ASP Databases 2 February 23rd, 2005 11:55 PM
sql query VAL function itHighway Classic ASP Basics 1 February 23rd, 2005 11:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.