Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 If data exists in table

Author  Topic 

YogeshDesai
Posting Yak Master

136 Posts

Posted - 2007-05-23 : 05:54:15
Hi guys I am writing a simple query to insert record from one table to another table.
For this I am using following query

INSERT OutExcelTempDetails
(
ExcelTempDetailID,
ExcelTempID,
RowNumber,
ColumnNumber,
ColumnName,
Description
)
SELECT
ExcelTempDetailID,
ExcelTempID,
RowNumber,
ColumnNumber,
ColumnName,
Description
FROM ExcelTempDetails


now my problem is once it's fired It wil insert all the records from ExcelTempDetails,I want to excute it agin and do want to add previous record,I mean how can I check for the prevoius values,If it already exist Ity should have to ignore them and want to insert only new values updated in ExcelTempDetails


Please help me to solve this issue,I just wanna avoid repetations



Yogesh V. Desai. | SQLDBA|

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-05-23 : 06:30:27

INSERT OutExcelTempDetails
(
ExcelTempDetailID,
ExcelTempID,
RowNumber,
ColumnNumber,
ColumnName,
Description
)
SELECT
ExcelTempDetailID,
ExcelTempID,
RowNumber,
ColumnNumber,
ColumnName,
Description
FROM ExcelTempDetails T
Where not exists
(Select * from OutExcelTempDetails where ExcelTempDetailID=T.ExcelTempDetailID)

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

YogeshDesai
Posting Yak Master

136 Posts

Posted - 2007-05-23 : 06:47:49
Hi madhivanan
Thank you very much for your quick help,It's working fine.Thanks dear friend for your helpand your time.

Yogesh V. Desai. | SQLDBA|
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-05-23 : 07:35:18
quote:
Originally posted by YogeshDesai

Hi madhivanan
Thank you very much for your quick help,It's working fine.Thanks dear friend for your helpand your time.

Yogesh V. Desai. | SQLDBA|


You are welcome

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -