Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

the linked server insert data to csv in wrong order

Status
Not open for further replies.

botatun

Programmer
Mar 7, 2006
40
US
Hi all,
I tried to import data to csv file by using linked server
the data transfers but it sort by last column.
Code:
....
EXEC sp_addlinkedserver N'Account', N'Jet 4.0', 
   N'Microsoft.Jet.OLEDB.4.0',
   N'C:\RexxxxlCxxxxxs\Exxxt',
   NULL,
   N'Text';
GO

EXEC sp_addlinkedsrvlogin 'Account'
GO

EXEC xp_cmdshell 'echo "DOC_ID","BUS_DAT","PMT_SEQ_NO","CR_CARD_NO"> C:\MyServer\RexxxxlCxxxxxs\Exxxt\LPI_5_PS_TKT_HIST_PMT_CR_CARD.csv';
GO

insert into Account...LPI_5_PS_TKT_HIST_PMT_CR_CARD#csv
  SELECT  
  DOC_ID,CONVERT(VARCHAR(10),[BUS_DAT],101) + ' ' + substring(CONVERT(VARCHAR(30),[BUS_DAT],109),13, 26),
  PMT_SEQ_NO,CR_CARD_NO_MSK
  FROM [RetailConcepts].[dbo].[PS_TKT_HIST_PMT_CR_CARD]
where convert(varchar(10),bus_dat,120) 
   >= convert(varchar(10),'2012-05-30T00:00:00.000',120)
and convert(varchar(10),bus_dat,120) 
   <= convert(varchar(10),'2012-05-30T00:00:00.000',120)
order by doc_id
go

when I open file in Excel or notepad it sort by CR_CARD_NO_MSK
instead of doc_id.
How could I fixed it?
Vadim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top