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
 Import/Export (DTS) and Replication (2000)
 VIEW IN TRIGGER

Author  Topic 

muhiar
Starting Member

37 Posts

Posted - 2005-11-30 : 08:31:38
can i use view in the trigger?
what is the syntax????????????
can i bcp a view ???

nr
SQLTeam MVY

12543 Posts

Posted - 2005-11-30 : 13:20:05
yes and yes.
in both cases reference the view in the same way as you would a table.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

muhiar
Starting Member

37 Posts

Posted - 2005-12-01 : 01:46:39
I mean creating a view inside the trigger and then drop it in the same procedure
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2005-12-01 : 01:53:59
quote:
Originally posted by muhiar

I mean creating a view inside the trigger and then drop it in the same procedure


why do you want to do this inside the trigger ?

-----------------
[KH]
Go to Top of Page

shallu1_gupta
Constraint Violating Yak Guru

394 Posts

Posted - 2005-12-01 : 01:55:17
no i think that is not allowed but
why do u want to do that?
Go to Top of Page

muhiar
Starting Member

37 Posts

Posted - 2005-12-01 : 02:48:44
I tried to select the values of inserted into the view then do bcp to the view
since the bcp can not see the inserted table
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-12-01 : 03:29:21
Do you need to BCP it out immediately, or could the trigger put the data into a "staging" table and then a batch job do the BCP (each hour, or whatever)?

Kristen
Go to Top of Page

muhiar
Starting Member

37 Posts

Posted - 2005-12-01 : 04:26:37
i want to do the following
when user insert a record ,the after insert trigger emport that record into a file
i tried to use the bcp where the pk of the table = pk inserted in the inserted table
but it still hang
so i thought about the view as solution(or local table created in the trigger and droped at the end of the trigger

Go to Top of Page

shallu1_gupta
Constraint Violating Yak Guru

394 Posts

Posted - 2005-12-01 : 05:04:05
U can try this
get the values inserted in local variables
like
Select @Var1= col1, @var2= Col2 ...from inserted
and execute bcp dynamically
@sqlstring = 'bcp "Select' +@var1 +','+ @var2 +'" queryout c:\textfile.txt'
EXEC master..xp_cmdshell @sqlstring


Go to Top of Page

muhiar
Starting Member

37 Posts

Posted - 2005-12-01 : 06:41:44
i have tried it tell invalid column name for the @var value
Go to Top of Page

shallu1_gupta
Constraint Violating Yak Guru

394 Posts

Posted - 2005-12-01 : 06:47:40
post the exact details what u r trying alongwith the error u r getting.
add print @sqlstring and check whether the bcp command is properly getting build or not
Go to Top of Page
   

- Advertisement -