2012-06-15 71 views
2

我对Sybase存储过程的语法不是很熟悉。我得到一个错误与字符串连接:在Sybase存储过程中连接两个字符串

create procedure calendarList 
as 
declare @city varchar(20) 
declare @aus varchar(20) 
declare @combined varchar(200) 
declare @result varchar(200) 

declare curs cursor for select distinct M_CTN from UnionCal for read only 

open curs 

fetch curs into @city 

while (@@sqlstatus!=2) 
begin 
    declare curs2 cursor for 
    select * from UnionCal where [email protected] for read only 

    open curs2 
    fetch curs2 into @aus 

    while (@@sqlstatus!=2) 
    begin 
     @combined = @combined + ";" + @aus 
     fetch curs2 into @aus 
    end 

    fetch curs into @city 

    select @city,@aus 
    close curs2 

end 

close curs 

return 

的错误是在这一行:

@combined = @combined + ";" + @aus 

的错误信息是不是非常有帮助:

消息102,15级,状态1 服务器'DS_LN_D01_X0427',过程'calendarList',第24行 '@combined'附近的语法不正确。

显然我没有以正确的方式连接字符串。有任何想法吗?

我使用Sybase 12

+0

东西|| otherStuff不起作用?还有一点就是@combined不是初始化的... –

+0

@Spaeth nope,它不起作用。 –

+0

你试过初始化它吗? –

回答

4

这是很简单的只是命令前加SELECTSET

SELECT @combined = @combined + ";" + @aus 

SET @combined = @combined + ";" + @aus