declare @@CSNum int,@Cou int ,@csname varchar(10)set @@CSNum=20
set @Cou=1
while @@CSNum>0 begin
set @Cou=@Cou+1
set @csname='CS' + @Cou
create table @csname -- //第17行语法错误
(
AUTOID CHAR(10) NOT NULL,
CSID CHAR(10) NOT NULL,
Na char(10) not null,
Area char(10) not null,
TIN datetime not null,
TOUT datetime not null,
DIR int not null,
DI float(8),
DO float(8),
CRC char(10),
constraint pk_xxk primary key(AUTOID)
)
set @@CSNum=@@CSNum-1
if @@CSNum=0
BEGIN
PRINT '---END---'
break
END
end出现这个错误:
服务器: 消息 170,级别 15,状态 1,行 13
第 13 行: '@csname' 附近有语法错误。
set @Cou=1
while @@CSNum>0 begin
set @Cou=@Cou+1
set @csname='CS' + @Cou
create table @csname -- //第17行语法错误
(
AUTOID CHAR(10) NOT NULL,
CSID CHAR(10) NOT NULL,
Na char(10) not null,
Area char(10) not null,
TIN datetime not null,
TOUT datetime not null,
DIR int not null,
DI float(8),
DO float(8),
CRC char(10),
constraint pk_xxk primary key(AUTOID)
)
set @@CSNum=@@CSNum-1
if @@CSNum=0
BEGIN
PRINT '---END---'
break
END
end出现这个错误:
服务器: 消息 170,级别 15,状态 1,行 13
第 13 行: '@csname' 附近有语法错误。
set @csname='CS' + CAST(@Cou AS varchar(12))
或者
set @csname='CS' + CONVERT(varchar(12), @Cou)