-1

我有列的表

1_number varchar(50),
name_surname varchar(150),
myID int, 
2_number varchar(50)

有存储过程,我想在其中插入值

@1_number varchar(50),
@name_surname varchar(150),
@myID int,
@2_number varchar(50)

AS
BEGIN
SET NOCOUNT ON;

if not exists(SELECT * FROM myData WHERE 2_number= @2_number)

INSERT INTO myData(1_number,name_surname,myID,2_number)
 values (@1_number,@name_surname,@myID,@2_number)

但是有一个错误:列名“myID”无效。我的表中已经有此列

4

2 回答 2

1

尝试这个

创建过程 sp_myData

(@1_number varchar(50),

@name_surname varchar(150),

@myID 整数,

@2_number varchar(50))

作为

开始

声明@count int=0

设置无计数;

SELECT @count=count(*) FROM myData WHERE [2_number]= @2_number

如果(@count<1)

插入 myData([1_number],name_surname,myID,[2_number]) 值 (@1_number,@name_surname,@myID,@2_number)

结尾

于 2013-07-03T11:18:29.713 回答
1

你能试试这个吗..它可能有用

INSERT INTO myData([1_number],name_surname,myID,[2_number])
 values (@1_number,@name_surname,@myID,@2_number)
于 2013-07-03T10:38:15.080 回答