我的存储过程错在那里?
我想利用存储过程创建一个临时表,请便我看看错在那里,他的表名和主键是动态的。报错在:
/*
create table @ResultTableName
(
Resultcode NUMERIC(20) IDENTITY(1,1) not null,
SourceObjName varchar(20) not null, nfo VARCHAR(256) null /*摘要描述*/
CONSTRAINT @PrimeKey PRIMARY KEY CLUSTERED (Resultcode)
)
*/
我的存储过程是:
CREATE PROCEDURE sp_CreateTable
AS
begin
declare @ncnt int
declare @ResultTableName varchar(14)
declare @PrimeKey varchar(20)
select @ncnt=count(name) FROM sysobjects
WHERE name like 'Result%' and convert(char(8),substring(name,7,6),112)=substring(convert(char(8),getdate(),112),1,6)
--创建临时 表
if @ncnt=0
begin
select @ResultTableName = 'Result'+substring(convert(char(8),getdate(),112),1,6)
select @PrimeKey ='pk_'+@ResultTableName
/*
create table @ResultTableName
(
Resultcode NUMERIC(20) IDENTITY(1,1) not null,
SourceObjName varchar(20) not null, nfo VARCHAR(256) null /*摘要描述*/
CONSTRAINT @PrimeKey PRIMARY KEY CLUSTERED (Resultcode)
)
*/
end
end
|