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)
 Help with View

Author  Topic 

raxbat
Yak Posting Veteran

52 Posts

Posted - 2007-12-11 : 01:05:54
Hello All!

I have a view which returns some data! And I have a table with the same structure as a view! How do I insert(or update if row already present) view results into the table?

Thank You

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-12-11 : 01:57:25

Insert new data

Insert into table(columns)
select columns from view v
where not exists(select * from table where keycol=v.keycol)

Update existing data

Update t
set col1=v.col1,...
from table t inner join view v
on t.keycol=v.keycol

Madhivanan

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

raxbat
Yak Posting Veteran

52 Posts

Posted - 2007-12-11 : 01:58:05
Thanx a lot :)
Go to Top of Page
   

- Advertisement -