0% found this document useful (0 votes)
22 views

Create Procedure Genera

This document contains code to generate a unique product code in SQL Server. It defines a stored procedure that takes the maximum existing product ID, prefixes it with "C", and increments the number. It then calls this procedure and prints the output ID. It also shows VB code to call the procedure and assign the output to a textbox for a new product.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Create Procedure Genera

This document contains code to generate a unique product code in SQL Server. It defines a stored procedure that takes the maximum existing product ID, prefixes it with "C", and increments the number. It then calls this procedure and prints the output ID. It also shows VB code to call the procedure and assign the output to a textbox for a new product.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Copiar Codigo siguiente en SQL Server

create procedure Genera_Codigo


@id char(5) output
as
set @id=(Select max(idproducto) from Productos)
set @id=ISNULL(@id,'0000')
set @id='C'+RIGHT('0000'+RTRIM(RIGHT(@id,4)+1),4)

declare @id char(5)
exec genera_codigo @id output
print @id


Copiar Codigo 8oton Nuevo

rvate Sub btnuuevo_C1ck{8yva1 sender ^s System.0bect, 8yva1 e ^s
System.Lvent^rgs) uand1es btnuuevo.C1ck
cmd = uew Sq1Command{"genera_Codgo")
cmd.Command1ype = Command1ype.Storedrocedure
cmd.Connecton = cn
0m prm ^s uew Sq1arameter{"d", Sq10b1ype.Char, S)
prm.0recton = arameter0recton.0utput
cmd.arameters.^dd{prm)
cn.0pen{)
cmd.Lxecuteuonquery{)
cn.C1ose{)
txtd.1ext = prm.va1ue
Lnd Sub

You might also like