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.
| Author |
Topic |
|
alucado
Starting Member
4 Posts |
Posted - 2008-09-22 : 03:28:08
|
| I have a trigger and store procedure. pls see below code. Code Snippetcreate trigger utr_a on tableA after update as beginselect * into dbo.tmp from inserted exec usp_bendGocreate procedure usp_b as select * from dbo.tmp Go Because table dbo.tmp had been updated at the trigger utr_a, table dbo.tmp need be used at the procedure usp_b before trigger utr_a was be commited. system will block the one trans. how to solve it? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-22 : 03:35:49
|
| why are you using select * into inside trigger? this will cause an error when subsequent updates happen? |
 |
|
|
alucado
Starting Member
4 Posts |
Posted - 2008-09-22 : 04:20:54
|
| Because I want to export inserted data to external file. for example, txt or xml.And exec sp_xpcmdshell "bcp ****" can't be supported inside trigger. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-22 : 04:54:46
|
quote: Originally posted by alucado Because I want to export inserted data to external file. for example, txt or xml.And exec sp_xpcmdshell "bcp ****" can't be supported inside trigger.
ok. even then you could simply use insert... select to insert into tmp. why create table each time? |
 |
|
|
alucado
Starting Member
4 Posts |
Posted - 2008-09-22 : 09:27:43
|
| I think the main point is not select * into or insert into...select to.I want to run two transactions at the one trigger. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-22 : 09:30:34
|
quote: Originally posted by alucado I think the main point is not select * into or insert into...select to.I want to run two transactions at the one trigger.
ok. even in that case what i told is worth looking at. For first update it will work fine. for subsequent updates it will fail as it again tries to create table which already exists.I cant understand which two transactions you're refering to.i cant see any explicit transactions inside trigger code. |
 |
|
|
alucado
Starting Member
4 Posts |
Posted - 2008-09-22 : 10:00:37
|
| OK, I paste my sql code.CREATE TRIGGER UTR_ExportPL ON sdbc1..OR033100AFTER UPDATE ASIF UPDATE(or03013) AND EXISTS(SELECT 1 FROM inserted WHERE or03013=2) AND EXISTS(SELECT 1 FROM deleted WHERE or03013<>2)BEGIN INSERT into tmp_insert SELECT OR01001,OR03051,OR01004,SL01002,C.OR04003,OR01013,OR01018,OR01072,OR03001,OR03019,OR03046,OR03005,OR03002,OR03006,OR03011 FROM insertedLEFT JOIN OR013100 ON OR03001=OR01001LEFT JOIN SL013100 ON OR01004=SL01001LEFT JOIN (SELECT OR04001,OR04003 FROM OR043100 RIGHT OUTER JOIN or013100 ON OR04001=OR01001 WHERE OR04003 IS NOT NULLAND or04001=(SELECT TOP (1) or03001 FROM inserted)UNION ALLSELECT A.OR01001,B.SL14004 FROM (SELECT OR01001,OR01004 FROM OR043100 RIGHT OUTER JOIN or013100 ON OR04001=OR01001 WHERE OR04003 IS NULLAND or01001=(SELECT TOP (1) or03001 FROM inserted)) ALEFT JOIN (SELECT * FROM SL143100 WHERE SL14002='00') B ON A.OR01004=B.SL14001 ) as CON OR01001=C.OR04001--export result of query to txt file.declare @date varchar(8),@filename varchar(30),@sql varchar(2000)set @filename='c:\PL'+convert(char(8),getdate(),112)+'.txt'SET @sql='bcp "select * from SDBC1.dbo.tmp_insert " queryout'+' '+@filename+' '+'-c -t \t -SCTCNL066 -Uscca -Pscca'EXEC master..xp_cmdshell @sqlDELETE FROM SDBC1.dbo.tmp_insertend |
 |
|
|
|
|
|
|
|