2012年2月23日星期四

bcp and order of rows in table

I am loading data from external program using bcp into a temp table.
I assumed that the rows would be loaded sequentially (same order as
file). Is there a option or some other method to load the data in the
same order as the records in the file. Here is what I'm trying to do:
SET @.C='bcp ##tkaladt in ' + @.dir + @.file + ' -f
e:\kaleida\smsadtimp.fmt -U bla -P blabla'
EXEC @.R = master.dbo.xp_cmdshell @.C
DECLARE c_adtrecs CURSOR
for
select * from ##tkaladt
process records in the order they are in the file.
A table is, per definition, not ordered. How about adding an identity column, letting SQL Server generate the
identity values as BCP inserts the rows and use that column in your SELECT statement's ORDER BY?
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
"Joe R" <jralabate@.kaleidahealth.org> wrote in message news:eQE13hGLEHA.2660@.TK2MSFTNGP09.phx.gbl...
> I am loading data from external program using bcp into a temp table.
> I assumed that the rows would be loaded sequentially (same order as
> file). Is there a option or some other method to load the data in the
> same order as the records in the file. Here is what I'm trying to do:
> SET @.C='bcp ##tkaladt in ' + @.dir + @.file + ' -f
> e:\kaleida\smsadtimp.fmt -U bla -P blabla'
>
> EXEC @.R = master.dbo.xp_cmdshell @.C
> DECLARE c_adtrecs CURSOR
> for
> select * from ##tkaladt
> process records in the order they are in the file.
>

没有评论:

发表评论