本文介绍了需要将多值传递给数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有10列text1,text2,... text10和text,我需要将这10列值存储在称为text的一列中.使用存储过程sql2008

i have 10 columns text1,text2, ... text10 and text ,i need to store these 10 column values in one column called text. using stored procedure sql2008

推荐答案

CREATE PROCEDURE dbo.insertTen
(
@Date Date,
@Value int,
@V0 NCHAR(10),
@V1 NCHAR(10),
@V2 NCHAR(10),
@V3 NCHAR(10),
@V4 NCHAR(10),
@V5 NCHAR(10),
@V6 NCHAR(10),
@V7 NCHAR(10),
@V8 NCHAR(10),
@V9 NCHAR(10)
)
AS
  DECLARE @Id int
  SELECT @Id = MAX(Id) FROM Customers
  SET @Id = @Id + 1
  INSERT INTO Customers (Id, Customer, Value, date)
     VALUES (@Id, @V0, @Value, @Date)
  SET @Id = @Id + 1
    INSERT INTO Customers (Id, Customer, Value, date)
     VALUES (@Id, @V1, @Value, @Date)
  SET @Id = @Id + 1
    INSERT INTO Customers (Id, Customer, Value, date)
     VALUES (@Id, @V2, @Value, @Date)
  SET @Id = @Id + 1
    INSERT INTO Customers (Id, Customer, Value, date)
     VALUES (@Id, @V3, @Value, @Date)
  SET @Id = @Id + 1
    INSERT INTO Customers (Id, Customer, Value, date)
     VALUES (@Id, @V4, @Value, @Date)
  SET @Id = @Id + 1
    INSERT INTO Customers (Id, Customer, Value, date)
     VALUES (@Id, @V5, @Value, @Date)
  SET @Id = @Id + 1
    INSERT INTO Customers (Id, Customer, Value, date)
     VALUES (@Id, @V6, @Value, @Date)
  SET @Id = @Id + 1
    INSERT INTO Customers (Id, Customer, Value, date)
     VALUES (@Id, @V7, @Value, @Date)
  SET @Id = @Id + 1
    INSERT INTO Customers (Id, Customer, Value, date)
     VALUES (@Id, @V8, @Value, @Date)
  SET @Id = @Id + 1
    INSERT INTO Customers (Id, Customer, Value, date)
     VALUES (@Id, @V9, @Value, @Date)
RETURN
GO


这篇关于需要将多值传递给数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 08:24