By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,594 Members | 2,062 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,594 IT Pros & Developers. It's quick & easy.

IF..Else statement in sql.

P: 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
Share this Question
Share on Google+
6 Replies


lotus18
100+
P: 866
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

P: 14
I mean using VB6 code
Dec 26 '07 #3

P: 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
Expert 5K+
P: 8,127
Before inserting the records you need to check for existance of the record using COUNT().
Dec 26 '07 #5

P: 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

Expert 5K+
P: 8,434
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

Post your reply

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