Avatar of RDB1369
RDB1369Flag 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
ASKER CERTIFIED SOLUTION
Avatar of DBARider
DBARider

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of RDB1369
RDB1369
Flag of United States of America image

ASKER

This worked perfectly.  Thanks.
Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo