Hi, maybe this can help you. i did a similiar thing to what you are trying, just adapt your temp table and select query for the BCP...
CREATE PROCEDURE [dbo].[PROC_NAME]
AS
BEGIN
declare @CLOCKINGS varchar(100)
declare @LogID varchar(100)
declare @clock varchar (255)
DECLARE @bcpCommand varchar(2000)
declare @error varchar (100)
-- Create temp table to store data
create table Temp_Table (CLOCK varchar(255),
[LogID] [nvarchar](32) NULL,)
-- Create a new cursor
declare temp_cursor cursor for
select ssMainData.dbo.CLOCKINGS.[FILE], ssMainData.dbo.CLOCKINGS.LogID
from ssMainData.dbo.CLOCKINGS
-- Open the cursor and retrieve the first record
open temp_cursor
fetch next from temp_cursor
into @CLOCKINGS, @LogID
--- Loop through the recordset and add data to temp table
while @@fetch_status = 0
begin
insert into Temp_Table
values (@CLOCKINGS, @LogID)
---Fetch next record from the recordset
fetch next from temp_cursor
into @CLOCKINGS, @LogID
end
-- Close the cursor and release resources
close temp_cursor
deallocate temp_cursor
begin
--- Create import file using BCP through xp_cmdshell
SET @bcpCommand = 'bcp "select ssMainData..TEMP_TABLE.CLOCK FROM ssMainData..TEMP_TABLE" queryout c:\dump.txt -T -S CVE\CVE -c -t'
EXEC ssMainData..xp_cmdshell @bcpCommand
END
--- Drop temp_table
begin
drop table ssmaindata..temp_table
end
end
hope it helps...
Clive