digamos que simpre va a ser FA001,FA010,FA100 hasta FA999 right?
pues podemos hacerlo asi:
Código SQL:
Ver originalCREATE TABLE #temp
(
valor VARCHAR(20)
)
INSERT INTO #temp VALUES ('FA001')
INSERT INTO #temp VALUES ('FA002')
INSERT INTO #temp VALUES ('FA003')
INSERT INTO #temp VALUES ('FA004')
INSERT INTO #temp VALUES ('FA005')
INSERT INTO #temp VALUES ('FA009')
INSERT INTO #temp VALUES ('FA099')
SELECT
'FA' +
REPLICATE('0',3-
len(
CONVERT(VARCHAR(20),
MAX(CONVERT(INT,SUBSTRING(valor,CHARINDEX('0',valor,1),len(valor))))+1
)
)) +
CONVERT(VARCHAR(20),
MAX(CONVERT(INT,SUBSTRING(valor,CHARINDEX('0',valor,1),len(valor))))+1
)
FROM #temp
en procedure o funcion ya depende para que lo vas a usar :)
saludos!