Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2003
    Posts
    78

    Question Unanswered: Cast/Convert value to VB variable

    Hi all,
    I have a VB 6.0 application that interacts with an MS Access backend. I am in the process of converting it so that it interacts with SQL Server 2000. The current applications uses Cint, CStr, etc. functions which are MS-Access specific, so I am now switching over to Convert (or Cast) function. The problem is that there are certain places wherein I first need to store the value of the resultant CAST/Convert function in a variable and then use that value in a SQL statement. However, I cant seem to figure out a way of storing the results from CAST/CONVERT functions in the VB 6.0 variable. All the examples on Internet show use of these functions directly in an SQL statement e.g. "Select CAST(title as Int) from xyz", etc.
    Can anybody tell me how can i get the values to be stored in the variable? I am really stuck here and cant seem to progress.

    Thanks in advance for all your help.

    Regards:
    Prathmesh

  2. #2
    Join Date
    May 2002
    Posts
    299
    e.g.

    set rs=cmd.execute("select cast(title as int) as title from xyz")

    title=rs.fields("title")
    --
    -oj
    http://www.rac4sql.net

  3. #3
    Join Date
    Oct 2003
    Posts
    78
    Thanks for the reply oj. However, my requirement is somewhat different. I'll explain the scenario in short. The user chooses a filename to delete, which is stored in the database as a record. It is stored in 2 places in the database. One as a whole filename and in the second place as a breakdown record. The program should delete the filename from the database and also the file from the disk location. The filename in the database is stored as say "XY006CV003A.xls" or "XY005CJ003B.doc" however on the disk they are stored with the above number and the title for the document, concatenated e.g "XY006CV003A test.xls". So I need to extract the file name only which is "XY006CV003A.xls" to match the database record. The last part "003" is sort of a sequence number and is stored in the database. I need to extract the that sequence to match it and delete it from the second place as I have mentioned. '003' when extracted from the filename will be a string and I need to cast it to Integer type to match the record.

    e.g.
    fname = Split("XY006CV003A.xls",".") gives "XY006CV003A"
    seq = Mid(fname, 8, 3) gives '003' which is string format

    I now need to use this seq variable in the query

    "Select * from XYZ where fileseq=" & seq

    fileseq is of integer datatype so I need to cast/convert seq variable to Integer from String.
    Can anybody suggest any ideas?

    Regards:
    Prathmesh

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •