IF..Else statement in sql.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • elbatz
    New Member
    • Dec 2007
    • 14

    IF..Else statement in sql.

    How can i make an if else statement where the condition is in sql.for example:\

    if data exist then
    delete the old and insert the new data

    else
    insert new data.

    Thank you.
  • lotus18
    Contributor
    • Nov 2007
    • 865

    #2
    Originally posted by elbatz
    How can i make an if else statement where the condition is in sql.for example:\

    if data exist then
    delete the old and insert the new data

    else
    insert new data.

    Thank you.
    Hi

    I think this should be moved to database forum. Why don't you use Update Query
    ?

    Rey Sean

    Comment

    • elbatz
      New Member
      • Dec 2007
      • 14

      #3
      I mean using VB6 code

      Comment

      • elbatz
        New Member
        • Dec 2007
        • 14

        #4
        sorry for unclear question.i am creating a vb6 project which transfer records from excel to access. I have read some threads that shows how to transfer the records and it works in my project.My only problem is..what if the data from excel already exist in access table and therefore it shoudn't append to the table or else the old records in access table will be replaced by the records coming from excel worksheet.by the way i/m not using primary key because my reference key is not unique.

        Does IF..Else statement can be used in this case?

        I hope my question is clear to you.Thanks A lot

        Comment

        • debasisdas
          Recognized Expert Expert
          • Dec 2006
          • 8119

          #5
          Before inserting the records you need to check for existance of the record using COUNT().

          Comment

          • elbatz
            New Member
            • Dec 2007
            • 14

            #6
            Here's an example: I have a database BillMatch w/ table Bill. excel files to be exported to Bill.mdb are TB111.xls, TB222.xls, TB333.xls and so on. column1=Bill# ,column2=Name.

            I am going to insert the records from TB111.xls sheet1 and other xls file to Bill.mdb..Now, what if I am going to insert again the records from TB111.xls because TB111.xls has been updated having only 1 Bill# = 111. The records from Bill.mdb having Bill# =111 should be replaced by the records coming from the updated TB111.xls..How I am going to code this? Please help me 'coz I need to finish this Project today. Thanks a lot again.

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              Well, I guess it's too late now. But it seems to me the simplest thing would be to start out by telling the database to delete the records, then insert them. That way, it doesn't matter whether they existed there or not.

              Comment

              Working...