Results 1 to 8 of 8

Thread: SQL Question...

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    In front of Computer
    Posts
    37
    I am appending data to a table. One of the columns in the database is a numeric field, and some data coming in is the letter "x" which messes things up, how can i convert the "x" to "999" on the way in?

  2. #2
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    Can you supply more details? Where is the input data coming from? Can you show some of your code?
    "It's cold gin time again ..."

    Check out my website here.

  3. #3
    Addicted Member
    Join Date
    Jul 1999
    Location
    St-Élie d'Orford, Quebec, Canada
    Posts
    133
    Hi,

    you should be more concerned about how to stop the x from the input than how to patch this case...

    However (even if I'm not pro-patch) you could try a trigger on INSERT of SQL server that is, if your database is SQL SERVER driven ! This trigger could select from the "Inserted" table of the database and test for numeric values. If not numeric then update the "Inserted" table with the numeric value you want...

    E-mail me for details at [email protected] if needed...

  4. #4

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    In front of Computer
    Posts
    37
    ok the data is coming from a text delimited file that is exported off an AS400, and is a linked table in the database. Here is what i do to append all the items that dont have 'x' in the field

    Code:
    sSQL = "INSERT INTO Sales (Customer_No, Customer_Name, Sales_1, Sales_2, Sales_3, Sales_4, Sales_5, Sales_6, Sales_7) " & _
    "SELECT Mmarptcsv.Field2, Mmarptcsv.Field3, Mmarptcsv.Field4, Mmarptcsv.Field5, Mmarptcsv.Field6, Mmarptcsv.Field7, Mmarptcsv.Field8, Mmarptcsv.Field9, Mmarptcsv.Field10 " & _
    "From Mmarptcsv " & _
    "WHERE FIELD1 <> 'x'"
    dbSalesman.Execute sSQL
    now how can i convert the x to 999 and then append those records.


  5. #5
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    You could select the data into a temporary table, then run SQL updates and finally append the records from the temporary table.

    select * into temptable from Mmarptcsv
    update temptable set field4='999' where field4='x'
    [...]
    update temptable set field10='999' where field10='x'
    insert into Sales(...) select [...] from temptable

  6. #6

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    In front of Computer
    Posts
    37
    thx, i will try that tonight, and see how it werks, looks good though.

    thx

  7. #7
    Addicted Member JasonGS's Avatar
    Join Date
    May 2000
    Location
    California
    Posts
    155
    Im not sure if this is applicable, but if im reading from a field where the user should have entered a number, ill often force it to a Integer or Numeric Value with Int(X) or Val(X), example below:
    Code:
    ' With ADO
    adoRset.Update "id", Int(txtID.Text)
    
    ' SQL too
    adoConn.Execute "UPDATE mytable SET id = " & Int(txtID.Text) & " WHERE id = 0"

  8. #8
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Code:
    sSQL = "INSERT INTO Sales (Customer_No, Customer_Name, Sales_1, Sales_2, Sales_3, Sales_4, Sales_5, Sales_6, Sales_7) " & _
    "SELECT Mmarptcsv.Field2, Mmarptcsv.Field3, Mmarptcsv.Field4, Mmarptcsv.Field5, Mmarptcsv.Field6, Mmarptcsv.Field7, Mmarptcsv.Field8, Mmarptcsv.Field9, Mmarptcsv.Field10 " & _
    "From Mmarptcsv " & _
    "WHERE Mmarptcsv.FIELD1 <> 'x'"
    dbSalesman.Execute sSQL
    Hope this is working.

Posting Permissions

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



Click Here to Expand Forum to Full Width