하나의 테이블이 employeeId에 의해 조인되는 세 개의 테이블이 있습니다. 정상적인 SQL 문을 가입하게 한 열의 세 가지 값을 반환 - 그러나, 내가 즉, 대신에 내가로 반환해야sql curser는 하나의 값만 반환합니다.
Harry Tuttle
Sam Lowrey
Jack Lint
의 단일 문자열로이 값을 표시해야
Harry Tuttle, Sam Lowrey, Jack Lint
저장 프로 시저를 생성하고 아래에 포함 된 커서 (첫 번째 시도)를 사용하고 있습니다. 단지 문제는 실행될 때마다 실행하고 반환하는 것입니다.
Sam Lowrey,
내가 스크립트를 변경하고 I가 while 루프 세그먼트를 변경하는 경우 예 다른 SquirrleSQL 창에 출력을 생성 할 수 있습니다
create procedure sp_ac_temp (@assignmment_id int)
as
/* declare local variables used for fetch */
declare @advisor_name varchar(100)
/* cursor to get each advisor name */
declare advisor_fetch cursor for
select e.first_name + ' ' + e.last_name + ', '
from assign a
inner join advisor fa on a.assignment_id = fa.assignment_id
inner join employee e on fa.employee_id = e.employee_id
where a.assignment_id = @assignmment_id
open advisor_fetch
fetch advisor_fetch
into @advisor_name
if (@@sqlstatus = 2)
begin
close advisor_fetch
return
end
/* if cursor result set is not empty, process each row of information */
while (@@sqlstatus = 0)
begin
--if (@advisor_name != NULL)
begin
select @advisor_name = @advisor_name + '! '
end
fetch advisor_fetch into @advisor_name
select @advisor_name
end
것처럼 PROC 보이는 :
while (@@sqlstatus = 0)
begin
--if (@advisor_name != NULL)
begin
select @advisor_name = @advisor_name + '! '
select @advisor_name --this here
end
fetch advisor_fetch into @advisor_name
select @advisor_name
end
이 커서 6 번 반복되어 보여줍니다 (I 각각 하나의 이름을 포함하는 6 개의 IDE 프레임이 생성 되나, 그들은 다양합니다 :
Harry Tuttle, !
Sam Lowrey,
Sam Lowrey, !
Jack Lint,
Jack Lint,
Jack Lint, !
)).
Sybase를 사용하고 있습니다. 어떤 아이디어?
'@ advisor_name' (으)로 가져올 때마다 이전에 있던 내용을 덮어 씁니다. 답을 누적하기 위해 다른 변수가 필요합니다. – Laurence
이것을 달성하는 방법을 모르십니까? –