DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Data Type Conversion of Recordset Value

  1. #1
    Christian Flanagan Guest

    Data Type Conversion of Recordset Value


    I have a database that is all Text fields. I need to convert some of the fields
    returned to the recordset from a query to numeric values in order to use
    numeric comparison operators.

    Dim SQL As String
    Dim Mag As Double

    If cboMag.Text = "All" Then
    Mag = Null
    Else
    Mag = Val(cboMax.Text)
    End If


    SQL = "SELECT * FROM SAC70 WHERE MAG <= '*" & Mag & "*'"
    'The MAG Field from the database is a string. How do I convert it to a numeric
    value so that I can use the <= operator?
    Set RS = DB.OpenDatabase(SQL)

  2. #2
    Chris Ross Guest

    Re: Data Type Conversion of Recordset Value

    Did you have a look at the CAST or CONVERT functions for transact SQL?

    Try this -
    SQL = "SELECT * FROM SAC70 WHERE CAST(MAG as int) <= " & Mag & "'"

    I think this will work, so long as the MAG string is numbers.

    (Not sure how it will handle it when MAG is null, so you might want to code
    around that).

    Hope this helps.
    Chris Ross



    Christian Flanagan <cflanagan@vodavi.com> wrote in message
    news:3947c6dc$1@news.devx.com...
    >
    > I have a database that is all Text fields. I need to convert some of the

    fields
    > returned to the recordset from a query to numeric values in order to use
    > numeric comparison operators.
    >
    > Dim SQL As String
    > Dim Mag As Double
    >
    > If cboMag.Text = "All" Then
    > Mag = Null
    > Else
    > Mag = Val(cboMax.Text)
    > End If
    >
    >
    > SQL = "SELECT * FROM SAC70 WHERE MAG <= '*" & Mag & "*'"
    > 'The MAG Field from the database is a string. How do I convert it to a

    numeric
    > value so that I can use the <= operator?
    > Set RS = DB.OpenDatabase(SQL)




  3. #3
    Jeff Guest

    Re: Data Type Conversion of Recordset Value


    use the val function to convert the text into a number. i think a non-numeric
    will convert to a null.

    SQL = "SELECT * FROM SAC70 WHERE val(MAG) <= " & Mag



    "Christian Flanagan" <cflanagan@vodavi.com> wrote:
    >
    >I have a database that is all Text fields. I need to convert some of the

    fields
    >returned to the recordset from a query to numeric values in order to use
    >numeric comparison operators.
    >
    >Dim SQL As String
    >Dim Mag As Double
    >
    >If cboMag.Text = "All" Then
    > Mag = Null
    >Else
    > Mag = Val(cboMax.Text)
    >End If
    >
    >
    >SQL = "SELECT * FROM SAC70 WHERE MAG <= '*" & Mag & "*'"
    >'The MAG Field from the database is a string. How do I convert it to a numeric
    >value so that I can use the <= operator?
    >Set RS = DB.OpenDatabase(SQL)



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center