I have scenario, where I have to give sequence number for each record. And the sequence number should re-initialized to initial value if it is different account.
I was trying like this
declare @account_no varchar(50)
declare @seq_no int
declare @temp_no int
set @temp_no=1
select
(@account_no = (CASE WHEN @account_no <> PN.vst_int_id
THEN PN.vst_int_id
END))
,(@seq_no = (CASE WHEN @account_no = PN.vst_int_id
THEN @temp_no + 1
ELSE 1
END))
,@seq_no
,nte_pri_cd
from
TSM310_PATIENT_NOTES PN
where
vst_int_id = '4588611'