存储过程插入错误

时间:2013-07-03 10:22:55

标签: sql sql-server tsql

我有表格列

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'无效。 alreadey在我的表中有这个专栏

2 个答案:

答案 0 :(得分:1)

你能试试吗......可能会工作

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

答案 1 :(得分:1)

试试这个

CREATE PROCEDURE sp_myData

(@ 1_number varchar(50),

@name_surname varchar(150),

@myID int,

@ 2_number varchar(50))

AS

BEGIN

声明@count int = 0

设置NOCOUNT ON;

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

如果(@计数N 1)

INSERT INTO myData([1_number],name_surname,myID,[2_number])值(@ 1_number,@ name_surname,@ myID,@ 2_number)

END