-4

I have this kind of data in my table

lineid price €
01 100.00
02 200.00
01 10.34
01 311.12
01 14.33
02 36.44
03 89.70
04 11.33

and i would like my output to be like this

docid lineid price €
1 01 100
1 02 200.00
2 01 10.34
3 01 311.12
4 01 14.33
4 02 36.44
4 03 89.70
4 04 11.33

Its data for invoices and for every line that has lineid='01' it means that the info is for different invoice so i have to mark it with new documentID that i want you to help me create it with a command.

Its probably something easy but i am searching like a maniac here and i cant find the solution.

EDIT: Yes , it Is "increment docid each time lineid equals 01" what i want

Sokratis
  • 1
  • 1
  • You could use CASE and LAG here – Nathan_Sav Jul 04 '22 at 12:49
  • It's difficult to understand what you are asking about. Is it "increment docid each time lineid equals 01"? In that case, you must [define the order](https://stackoverflow.com/a/20050403/11683) of your lines first. And [tag your database](https://meta.stackoverflow.com/questions/388759/why-should-i-tag-my-rdbms). – GSerg Jul 04 '22 at 12:53
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jul 04 '22 at 17:03

1 Answers1

-1

You could use running counts using something like below (assuming this is MS SQL you are talking about)

SELECT ROW_NUMBER() over(partition by [LineId] order by [LineId]) as DocId,
      [LineId],
      [Price]
  FROM [StackOverflow].[dbo].[RunningCount] order by [LineId]
Danish
  • 136
  • 5