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 2005 Forums
 Transact-SQL (2005)
 Copying from a view to a table

Author  Topic 

sheridan111
Starting Member

1 Post

Posted - 2007-12-05 : 06:50:50
I am trying to write a sql statement which will copy values from a view to a table.

is there any way to create a trigger which fires on update, insert,

to copy any new data only from the view to the table

The view is called view_badge the table is called t_badge

i tried to create a procedure

create procedure update_view as
insert into t_badge select * from view_badge where
t_badge.stu_code != view_badge.stu_code

this query should only select values in view_badge which are not in t_badge but doesnt work

any help is appreciated.

Thanks,
Iain.



Iain M Campbell

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-12-05 : 06:53:01
[code]create procedure update_view
as

SET NOCOUNT ON

insert t_badge
select *
from view_badge
where not exists (select * from t_badge where t_badge.stu_code = view_badge.stu_code)[/code]


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2007-12-05 : 06:53:24
what table is the view over?

Em
Go to Top of Page
   

- Advertisement -