Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
This must be simple, but I cannot find a solution. I have a query that returns the payment plan for the orders. I need to number the payments but there is no such field in the database. Example of what I need:
My query returns the information except the installment number. How can I do that in a query without having to use a cursor to loop through a temp table to update that field?Thanks!Aécio Lemoshttp://www.vlsweb.com.brO primeiro provedor de hospedagem gerenciada do Brasil
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2008-08-02 : 05:40:41
something like this
SELECT IDENTITY(int,1,1) AS Sequence,ORDER_ID, TIMESTAMP, VALUE , TOTALINTO #TempFROM YourTableSELECT ORDER_ID, TIMESTAMP,(SELECT COUNT(*) FROM #Temp WHERE ORDER_ID=t.ORDER_ID AND ID<t.ID) + 1 AS INSTALLMENT, VALUE , TOTALFROM #Temp t