trigger

tema enviado por islu en SQL Server
tema iniciado el 14/07/2010
Necesito ayuda para insertar datos en una tabla y luego mandar los datos a un archivo .txt desde un trigger. tengo el código asi: set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER TRIGGER ins_fact_oinv ON dbo.OINV AFTER UPDATE AS BEGIN DELETE FROM [@FACTURAS]; SET NOCOUNT ON; INSERT INTO [@FACTURAS] (u_campo1, u_campo2, u_campo3, u_campo4, u_campo5 , u_campo6, u_campo7, u_campo8, u_campo9, u_campo10, u_campo11, u_campo12, u_campo13, u_campo14, u_campo15) SELECT '00', 'HP LaserJet 4050 Series PCL6','192.168.1.70', null, null, null, null, null, null, null, null, null, null, null, null UNION Select '01', '2.0', FolioPref, convert(char,FolioNum), convert(char(10),DocDate,103), null, null, null, null, Case When DocCur='MXP' Then convert(nvarchar,DocTotal-VatSum) Else convert(nvarchar,DocTotalFc-VatSumFc) End, null, null, Case When DocCur='MXP' Then Doctotal Else DoctotalFc End, null, null from inserted UNION Select '02', oadm.TaxIdNum, oadm.CompnyName, null, null, null, null, null, null, null, null, null, null, null, null From syc_pruebas.dbo.oadm UNION Select '03', substring(oadm.CompnyAddr,1,17), null,null,substring(oadm.CompnyAddr,19,19), null, null,substring(oadm.CompnyAddr,39,6), oadm.state , substring(oadm.CompnyAddr,39,6), substring(oadm.CompnyAddr,52,9), null, null, null, null From syc_pruebas.dbo.oadm UNION Select '04', null, null,null, null, null, null, oadm.state, substring(oadm.CompnyAddr,39,6), null, null, null, null, null, null From syc_pruebas.dbo.oadm UNION Select '05', LicTradNum, CardName, CardCode, convert(varchar,DocEntry), null, null, null, null, null, null, null, null, null, null From inserted UNION Select '06', ocrd.Address, null, null, ocrd.Block,null, null, ocrd.City, ocrd.State1, ocrd.Country , ocrd.ZipCode, null, null, null, null From syc_pruebas.dbo.ocrd INNER JOIN inserted i ON i.cardcode=ocrd.CardCode UNION Select '07', convert(varchar, inv1.U_Cantidad), null, convert(varchar,inv1.ItemCode), CASE WHEN convert(varchar(2500),oinv.U_Desc_Factura)<>'' THEN convert(varchar(2500),oinv.U_Desc_Factura) ELSE convert(varchar(2500),inv1.U_Desc_Extendida) END, inv1.Price , Case When inv1.Currency = 'MXP' Then INV1.LineTotal Else INV1.TotalFrgn End, null, null, null, null, null, null, null , null From inv1 INNER JOIN oinv ON oinv.DocEntry=inv1.DocEntry INNER JOIN inserted i ON oinv.DocEntry=i.DocEntry UNION Select '12', Case When inv1.Currency ='MXP' Then convert(char,inv1.Vatsum) Else convert(char,inv1.VatSumFrgn) End, null, null, null, null, null, null, null, null, null , null, null, null, null From syc_pruebas.dbo.inv1 INNER JOIN inserted i ON i.docentry=inv1.docentry UNION Select '14', 'IVA', convert(char,inv1.VatPrcnt), Case When inv1.Currency ='MXP' Then convert(char,inv1.Vatsum) Else convert(char,inv1.VatSumFrgn) End , null, null, null, null, null, null, null, null, null, null, null From syc_pruebas.dbo.inv1 INNER JOIN inserted i ON i.docentry=inv1.docentry UNION Select 'A0', null, null, null, null, null, null, null, null, null, null, null, null, null, null UNION Select 'A1', null, null, null, null, null, null, null, null, null, null, null, null, null, null UNION Select 'A2', null, null, null, null, null, null, null, null, null, null, null, null, null, null END Exec master..xp_cmdshell 'bcp "Select * From SYC_PRUEBAS.dbo.[@FACTURAS] " queryout "c:\facturacion\factsap.txt" -T -c -t"|"' Pero se queda pasmado el proceso.