Separate SQL Server counters

0

My question is as follows I have a calculated column that concatenates a value with the column number to generate the field:

CREATE TABLE #Ejemplo (
    ID INT IDENTITY, 
    NumeroRadicado AS ('AG' + RIGHT(REPLICATE('0', 15) + CONVERT(VARCHAR, ID),15)) PERSISTED NOT NULL, 
    Dato VARCHAR(255)
)

INSERT INTO #Ejemplo (Dato) VALUES ('Dato1') , ('Dato2')

SELECT  *
FROM #Ejemplo

Result:

╔══════╦═══════════════════╦═══════╗
║ ID   ║ NumeroRadicado    ║ Dato  ║
╠══════╬═══════════════════╬═══════╣
║ 1,00 ║ AG000000000000001 ║ Dato1 ║
╠══════╬═══════════════════╬═══════╣
║ 2,00 ║ AG000000000000002 ║ Dato2 ║
╚══════╩═══════════════════╩═══════╝

The question I have is, if it is possible to generate a table where the column of the counter is separated and when generating the insert this check in that other table to take the counter data

Thank you very much for your contributions

    
asked by Brian Velez 21.11.2018 в 22:14
source

0 answers