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 2008 Forums
 Transact-SQL (2008)
 Row number?

Author  Topic 

Pete_N
Posting Yak Master

181 Posts

Posted - 2012-01-09 : 07:30:09
The data is dunped into a table from a different system, read from a text file. I have no control over this.
Query

SELECT LedgerKey, TransactionIMPID, IMPSequence, ClientLedger, CreatedDate, CreatedUserID, DestSortCode, DestAccountNumber, DestAccountName,
DestBankRef, TransValue, TransCode, TransType
FROM tbBOSS_TransactionIMP

how can I add a row number without changing the order of the data

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-01-09 : 07:33:15
In SQL, by the very definition, data in a table have no order. So if the data is already in the table, the order of the data is lost.

If you are importing the data from somewhere that does have an order, for example from a csv file or excel file, you can include another column as you are importing it and have this new column hold a row number.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-09 : 07:35:27
first define your order as per sunita explanation and then you can generate the rownumber using window function ROW_NUMBER()

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-01-09 : 08:03:51
This may help you
http://beyondrelational.com/blogs/madhivanan/archive/2008/11/29/row-number-function-with-no-specific-order.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Pete_N
Posting Yak Master

181 Posts

Posted - 2012-01-09 : 08:28:14
quote:
Originally posted by madhivanan

This may help you
http://beyondrelational.com/blogs/madhivanan/archive/2008/11/29/row-number-function-with-no-specific-order.aspx

Madhivanan

Failing to plan is Planning to fail



Thank you, this resolves my problem
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-09 : 08:30:53
quote:
Originally posted by Pete_N

quote:
Originally posted by madhivanan

This may help you
http://beyondrelational.com/blogs/madhivanan/archive/2008/11/29/row-number-function-with-no-specific-order.aspx

Madhivanan

Failing to plan is Planning to fail



Thank you, this resolves my problem


keep in mind that it just numbers the dataset randomly without any order

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-01-09 : 08:31:55
quote:
Originally posted by Pete_N

quote:
Originally posted by madhivanan

This may help you
http://beyondrelational.com/blogs/madhivanan/archive/2008/11/29/row-number-function-with-no-specific-order.aspx

Madhivanan

Failing to plan is Planning to fail



Thank you, this resolves my problem


You are welcome

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -