-2

Below is the variable in Oracle I need to convert in SQL Server please suggest.

V_BAD_EMAIL_CNT NUMBER :=  REGEXP_COUNT(pv_bad_emails,',') + 1;
Dale K
  • 21,987
  • 13
  • 41
  • 69
Sag
  • 9
  • 2
  • 1
    As per the question guide, please show what you’ve tried and tell us what you found (on this site or elsewhere) and why it didn’t meet your needs. – Dale K Feb 10 '22 at 07:51
  • 1
    SQL Server doesn't support regex, so we would need to see exactly what pattern you are trying to count here. – Tim Biegeleisen Feb 10 '22 at 07:55

1 Answers1

1

This will return the number of comma's in the string + 1 in SQL

 declare @pv_bad_emails varchar(1000);
 set @pv_bad_emails = 'a,b,c,d';
 select len(@pv_bad_emails) - len(replace(@pv_bad_emails, ',', '')) + 1

For more reference

How do you count the number of occurrences of a certain substring in a SQL varchar?

Dale K
  • 21,987
  • 13
  • 41
  • 69
SV_
  • 34
  • 4