Avatar of RDB1369
RDB1369
Flag for United States of America asked on

SQL STATEMENT TO INCREMENT COUNTER BASED ON CRITERIA

I am buiding a view in SQL with information coming from two files.
File A has
Invoice Number
Flag if it has a Summary Invoice Number
File B has
Invoice Number
Summary Invoice Number

I want my view to have
Invoice Number, Summary Number, Counter

I want the counter to increase each time the same summary number is used.  If there is no summary invoice number the counter would be 1.

Example
Row 1
Invoice Number = 1
Summary Number = 100
Counter = 1
Row 2
Invoice Number = 2
Summary Number = 100
Counter = 2
Row 3
Invoice Number = 3
Summary Number = 200
Counter = 1
Row 4
Invoice Number = 4
Summary Number = NULL
Counter = 1


Can anyone help with the code for the counter
Microsoft SQL Server

Avatar of undefined
Last Comment
RDB1369

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
DBARider

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
RDB1369

ASKER
This worked perfectly.  Thanks.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy