1. Milton Jiménez
  2. SnapDevelop
  3. Friday, 17 July 2020 05:33 AM UTC

Hi,Friends, 


I use the function f_Secuencial(caja,tabla);for generate sequentials for my documents

the question is, using _context in c#; how replacement the following expressions

1. DO WHILE SQLCA.SqlDBCODE = 1205
2. IF SQLCA.SqlnRows = 0 then
3. IF SQLCA.SqlCode < 0 then
4. there is a more efficient way to carry consecutive in c# without using identities ?

 

Best Regards,

 

f_secuencial(caja,tabla)

SELECT pv_secuencia.seqno
INTO :secuencial
FROM pv_secuencia with(holdlock)
WHERE pv_secuencia.cod_compania ='1' and pv_secuencia.nr_caja=:caja and pv_secuencia.tipo_movimiento=:tabla ;

DO WHILE SQLCA.SqlDBCODE = 1205
FOR li_i = 1 to 200000
Next
SELECT pv_secuencia.seqno
INTO :secuencial
FROM pv_secuencia with(holdlock)
WHERE pv_secuencia.cod_compania ='1' and pv_secuencia.nr_caja=:caja and pv_secuencia.tipo_movimiento=:tabla ;
LOOP

IF SQLCA.SqlnRows = 0 then
gs_mensaje="SEQNO o"
f_mensajes(17)
return -1
rollback;
END IF

UPDATE pv_secuencia
SET SEQNO =SEQNO + 1
WHERE pv_secuencia.cod_compania ='1' and pv_secuencia.nr_caja=:caja and pv_secuencia.tipo_movimiento=:tabla ;

IF SQLCA.SqlCode < 0 then
gs_mensaje="anex_seqno"
f_mensajes(18)
rollback;
return -1
END IF

return secuencial

 

 

Accepted Answer
mike S Accepted Answer Pending Moderation
  1. Friday, 17 July 2020 14:26 PM UTC
  2. SnapDevelop
  3. # Permalink

that looks like SQL Server? If so then you should consider using sequences

https://docs.microsoft.com/en-us/sql/t-sql/statements/create-sequence-transact-sql?view=sql-server-ver15

- this way you don't need a loop

Comment
There are no comments made yet.


There are replies in this question but you are not allowed to view the replies from this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.