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)
 bcp and global table

Author  Topic 

muhiar
Starting Member

37 Posts

Posted - 2006-01-18 : 02:11:32
hi all
i want to export data as being inserted into text file
so i have created trigger after insert that select data from inserted table and echo it into text file
this works fine
but i want to add '-r' and '-n'
after each field
it seems that echo does not have it???
so i decided it create a global table in the after insert trigger
and insert all the values in inserted table then
use the bcp with format file
but the problem is that an error says invalid object for the global table??
can i use drop table ##global ????
if global table does not work can i use temp table #temp
instead and how???
thnx

nr
SQLTeam MVY

12543 Posts

Posted - 2006-01-20 : 10:38:38
Problem is (well one of them) that the trigger works in a transaction. The table you insert into would be locked and the bcp which works on a new connection would be blocked.
When you say '-r' and '-n' do you mean control characters or the four characters -r-n?
I suspect it's possible with the echo if you say what you aer trying to do.

==========================================
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 - 2006-01-22 : 01:55:07
i want to insert carriage return line feed after each field??
so it is not possible by bcp
???????????????????????????????
how can i do it by echo???? or any other ideas
Go to Top of Page

muhiar
Starting Member

37 Posts

Posted - 2006-01-23 : 03:11:02
hi all
i have tried the following code

create trigger t1 on authors
after insert
as
create table ##t ( c varchar(2000));

insert into ##t
select * from inserted;

set @bcpcmd = 'bcp "select * from ##t" queryout c:\t.txt -C -f c:\t1.txt'
exec master..xp_cmdshell @bcpcmd
drop table ##t;


but when ever i insert any record it takes for ever and no thing works?????????
any ideas
plz help its very urgent



Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-01-23 : 03:57:31
BCP is something that is a bad idea to do in a trigger.

You should look for a different solution.

CODO ERGO SUM
Go to Top of Page

muhiar
Starting Member

37 Posts

Posted - 2006-01-23 : 04:29:23
What other solution that can be done????????
i used echo but echo does not support carriage return and line feed
what shall i do???
plz help
Go to Top of Page
   

- Advertisement -