I have trying to determine a way of adding an incrementing number into a new table I have created with no luck. I have been bouncing back and forth between identity and row_number. My current code is using select identity. The table field is called cnt and the data type is int. I would like the number to start at 1 for the first record and increment by 1 for the rest of the records. Any help is appreciated.
Tom
Tom
Code:
DECLARE @entered datetime,@id int
SET @entered = Convert(varchar, getdate(), 110)
SET @id =SELECT IDENTITY(INT, 1, 1)
--INSERT INTO rptdata_monthly.dbo.rpt_EncounterCnts_1
--(cnt,year,month,uci,enc_cnt,cpt_cnt,procedures,entered)
SELECT @id,PER.yr as year,PER.monasdt as month,CS.uci,Sum(CS.enccnt),Sum(CS.cptcnt),Sum(CS.adjunits) as Procedures,@entered as entered
INTO rptdata_monthly.dbo.rpt_EncounterCnts_1
FROM rptdata_monthly.dbo.rpt_dat_CSDetail CS
JOIN rptdata_monthly.dbo.dic_Period PER ON PER.pd = CS.rptpd
WHERE CS.uci='ASO'
GROUP BY PER.yr,PER.monasdt,CS.uci
ORDER BY PER.yr,PER.monasdt,CS.uci