473,320 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

IF..Else statement in sql.

14
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.
Dec 26 '07 #1
6 2302
lotus18
866 512MB
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
Dec 26 '07 #2
elbatz
14
I mean using VB6 code
Dec 26 '07 #3
elbatz
14
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
Dec 26 '07 #4
debasisdas
8,127 Expert 4TB
Before inserting the records you need to check for existance of the record using COUNT().
Dec 26 '07 #5
elbatz
14
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.
Dec 26 '07 #6
Killer42
8,435 Expert 8TB
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.
Dec 29 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: dmbkiwi | last post by:
I am new to this group, and relatively new to python programming, however, have encountered a problem I just cannot solve through reading the documentation, and searching this group on google. I...
27
by: Ron Adam | last post by:
There seems to be a fair amount of discussion concerning flow control enhancements lately. with, do and dowhile, case, etc... So here's my flow control suggestion. ;-) It occurred to me (a...
3
by: Patrice | last post by:
Hi, I need to do multi-conditional statements like below, but this error is displayed : Expected 'End' /myFilepath, line x else response.write(arrCorpo(sparam,sdiv)) end if I don't...
6
by: Karen Middleton | last post by:
In MS Access I can do in one SQL statement a update if exists else a insert. Assuming my source staging table is called - SOURCE and my target table is called - DEST and both of them have the...
12
by: Roman Töngi | last post by:
In c++ there does not exist an if-statement as for example in Visual Basic, does it? //VB-analogy: if (cond.) statement; else if (cond.) statement; else statement;
5
by: WindAndWaves | last post by:
Hi Team The function below searches all the tables in a database. However, if subsearch = true then it searches all the objects listed in a recordset (which are all table names). I thought to...
18
by: swaroophr | last post by:
Which of switch statement and if-else statement takes less time to execute?
3
by: Amy | last post by:
Hi, I have 6 If Then Else statements I was supposed to write. I did so but I know that they have to be wrong because they all look the same. Could someone take a look at them and point me in the...
2
by: paul | last post by:
Hi all, I've been handed some code and, unless I've got the numbering of parentheses wrong, one of the functions has a curious if-else statement. The thing compiles but is it right? I know the...
20
by: John Salerno | last post by:
I'm starting out with this: try: if int(text) 0: return True else: self.error_message() return False except ValueError: self.error_message()
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.