Sql 为什么这个代码序列给我一个错误102
有人知道为什么这会给我一个错误102,错误的语法吗Sql 为什么这个代码序列给我一个错误102,sql,sql-server-2008,tsql,Sql,Sql Server 2008,Tsql,有人知道为什么这会给我一个错误102,错误的语法吗 declare @i int=20 while @i<=50 begin try if convert(char,getdate(),@i) is not null begin select convert(char,getdate(),@i) end set @i=@i+1 end try beg
declare @i int=20
while @i<=50
begin
try
if convert(char,getdate(),@i) is not null
begin
select convert(char,getdate(),@i)
end
set @i=@i+1
end try
begin catch
set @i=@i+1
end catch;
end
声明@i int=20
而@i则在结束捕捉之后删除分号,并在尝试之前添加开始
差不多
declare @i int=20
while @i<=50
begin
begin try
if convert(char,getdate(),@i) is not null
begin
select convert(char,getdate(),@i)
end
set @i=@i+1
end try
begin catch
set @i=@i+1
end catch
end
删除end catch之后的分号,并在尝试之前添加begin
差不多
declare @i int=20
while @i<=50
begin
begin try
if convert(char,getdate(),@i) is not null
begin
select convert(char,getdate(),@i)
end
set @i=@i+1
end try
begin catch
set @i=@i+1
end catch
end
根据你的缩进判断,我相信你想要第5行的begintry
。根据你的缩进判断,我相信你想要第5行的begintry
。是begintry
,而不仅仅是TRY
,因此TRY
之前的BEGIN
将与TRY
相关联。这意味着catch
结束于之外,而与try
分开,最后出现了一个过多的end
语句
因此,只需将try
更改为begintry
它是begintry
,而不仅仅是try
,因此try
之前的begin
将与try
关联。这意味着catch
结束于之外,而与try
分开,最后出现了一个过多的end
语句
因此,只需将try
更改为begintry
同样,在使用convert
时,您应该始终为目标变量指定一个显式长度。否则,您可能会得到一个令人不快的惊喜和一个长度为1个字符的变量……目标变量(在本例中为char)是否有时无法获得默认长度30?这是怎么回事,什么时候?它如何以长度1结束?另外,在使用转换
时,您应该始终为目标变量指定一个显式长度。否则,您可能会得到一个令人不快的惊喜和一个长度为1个字符的变量……目标变量(在本例中为char)是否有时无法获得默认长度30?这是怎么回事,什么时候?它如何以长度1结束?