all groups > sql server (alternate) > january 2007 >
You're in the

sql server (alternate)

group:

bcp & trigger: got missiing data in bcp out files


bcp & trigger: got missiing data in bcp out files danceli NO[at]SPAM gmail.com
1/31/2007 1:39:33 PM
sql server (alternate):
I have a trigger 'trgTblUpdate' working on the table 'Tbl'. When the
table 'Tbl' got inserted/updated data, the tigger is fired and then we
use a batch file with bcp command to unload those new inserted/updated
data to another server. But in bcp out file, it didn't get all new
inserted/updated data, there are some missing data. I am not sure if I
explain it clearly. Could you help me out of this problem???? I am
stuggling for that these two days............Any help is appreciated.

1. code for trigger:

CREATE TABLE [TblUpdate] (
[id] [int] NOT NULL ,
[eventid] [int] NOT NULL ,
[sequenceid] [int] NOT NULL ,
[UpdatePass] [int] NULL
) ON [PRIMARY]
GO
create trigger trgTblUpdate on Tbl For Insert,Update as
insert into TblUpdate(id,eventid,sequenceid) select ins.id,
ins.eventid,ins.sequenceid from inserted ins

2. bcp code in the Batch file:
isql -U <user> -P <pw> -S <server> -Q "update AA..TblUpdate set
UpdatePass=1 where UpdatePass is null"

bcp "select a.* from AA..Tbl a, AA..TblUpdate b where
a.eventid=b.eventid and a.sequenceid=b.sequenceid and b.eventid<>-1
and b.sequenceid<>-1 and b.updatepass=1" queryout 30sec-%TFN_NOW%.wrk -
U <user> -P <pw> -S <server> -f Tbl.fmt

isql -U <user> -P <pw> -S <server> -Q "delete from AA..TblUpdate where
UpdatePass=1"
Re: bcp & trigger: got missiing data in bcp out files Razvan Socol
2/5/2007 10:31:30 PM
Maybe you already had some rows with UpdatePass=1, before the update
was started. Or maybe you have some rows where the eventid and/or
sequenceid is not -1.

Razvan
AddThis Social Bookmark Button