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. |
 |
|
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 |
 |
|
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] |
 |
|
shallu1_gupta
Constraint Violating Yak Guru
394 Posts |
Posted - 2005-12-01 : 01:55:17
|
no i think that is not allowed butwhy do u want to do that? |
 |
|
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 viewsince the bcp can not see the inserted table |
 |
|
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 |
 |
|
muhiar
Starting Member
37 Posts |
Posted - 2005-12-01 : 04:26:37
|
i want to do the followingwhen 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 hangso i thought about the view as solution(or local table created in the trigger and droped at the end of the trigger |
 |
|
shallu1_gupta
Constraint Violating Yak Guru
394 Posts |
Posted - 2005-12-01 : 05:04:05
|
U can try thisget the values inserted in local variables likeSelect @Var1= col1, @var2= Col2 ...from insertedand execute bcp dynamically@sqlstring = 'bcp "Select' +@var1 +','+ @var2 +'" queryout c:\textfile.txt'EXEC master..xp_cmdshell @sqlstring |
 |
|
muhiar
Starting Member
37 Posts |
Posted - 2005-12-01 : 06:41:44
|
i have tried it tell invalid column name for the @var value |
 |
|
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 |
 |
|
|