助けてくれてありがとう
私は Asp.net ベースのプロジェクトに取り組んでおり、私の要件は、MaterialType+ProductID と - 4 桁の乱数の組み合わせで PARTNO を生成することです。
注: ProductID は主キーであり、出力パラメーターにも設定します
たとえば、材料タイプが 500 で、生成された製品 ID が 55 で、生成されたランダム番号が 5434 の場合、部品番号は 555-5434 になります。
私の質問は、どうすれば partno を同じテーブルに保存できるかということです。
        Connection.Open()
        Dim trn As SqlClient.SqlTransaction
        trn = Connection.BeginTransaction
        Using trn
            Dim sqlcode As New SqlParameter("@ProductID", Products.ProductID)
            sqlcode.Direction = ParameterDirection.InputOutput                 
            Using Command As New SqlCommand("Product_Write", Connection, trn)
                Command.CommandType = CommandType.StoredProcedure
                Command.Parameters.Add(sqlcode)                     Command.Parameters.AddWithValue("@MaterialType", Materialtype.MaterialTypeCode)
                Command.Parameters.AddWithValue("@CategoryID", category.CategoryId)
                Command.Parameters.AddWithValue("@ProductName", Products.ProductName)
                Command.Parameters.AddWithValue("@ProductDescription", Products.ProductDescription)
                Command.Parameters.AddWithValue("@ProductActive", Products.ProductActive)
                Command.Parameters.AddWithValue("@ProductImage", Products.ProductImage)
                Command.Parameters.AddWithValue("@PartNo", 0)
                Command.ExecuteNonQuery()
                Products.ProductID = CInt(sqlcode.Value)
                'Insert the part no 
                Dim random As New Random()
                Dim value As Integer = random.Next(9999)
                Dim PartNo As String = CType((Materialtype.MaterialTypeCode + Products.ProductID).ToString + "-" + value.ToString, String)
                'Dont know what to do 
                trn.Commit()
                Connection.Close()
            End Using
        End Using
    End Using
    Return Products
End Function
ALTER PROCEDURE [dbo].[Product_Write]
@ProductID bigint OUTPUT,
@MaterialType int,
@CategoryID bigint,
@ProductName VARCHAR(MAX),
@ProductDescription VARCHAR(MAX),
@ProductActive Bit,
@ProductImage VARCHAR(MAX),
@PartNo VARCHAR(30)
AS
IF (@ProductID=0)
BEGIN
INSERT INTO T_Product(
MaterialType,
CategoryID,
ProductName,
ProductDescription,
ProductActive,
ProductImage,
PartNo)
VALUES(
@MaterialType,
@CategoryID,
@ProductName,
@ProductDescription,
@ProductActive,
@ProductImage,
@PartNo)
SET @ProductID=SCOPE_IDENTITY()
END 
ELSE
 UPDATE T_Product SET
      MaterialType=@MaterialType,
      CategoryID=@CategoryID,
      ProductName=@ProductName,
      ProductDescription=@ProductDescription,
      ProductActive=@ProductActive,
      ProductImage=@ProductImage,
      PartNo=@PartNo
WHERE ProductID=@ProductID
                Please help me out
ありがとう