declare @id int,@title char(10),@str char(10),@lstr char(100)
declare my_cursor cursor for
select employeeid,titleofcourtesy
from employees
Open my_cursor
fetch my_cursor into @id,@title
while @@fetch_status=0
begin
set @lstr = @lstr+@title
print @lstr
fetch my_cursor into @id,@title
end
print @title
close my_cursor
deallocate my_cursor为什么打印出来是空白,好像不能循环连接?在线等...
declare my_cursor cursor for
select employeeid,titleofcourtesy
from employees
Open my_cursor
fetch my_cursor into @id,@title
while @@fetch_status=0
begin
set @lstr = @lstr+@title
print @lstr
fetch my_cursor into @id,@title
end
print @title
close my_cursor
deallocate my_cursor为什么打印出来是空白,好像不能循环连接?在线等...
print cAST(@lstr AS VARCHAR(10))
改为:
fetch next my_cursor into @id,@title 另外你检查一下数据源是不是空的?
declare my_cursor cursor for
select employeeid,titleofcourtesy
from employees
Open my_cursor
fetch my_cursor into @id,@title
while @@fetch_status=0
begin
set @lstr = @title
print @lstr
fetch my_cursor into @id,@title
end
close my_cursor
deallocate my_cursor这样就有数据
SET @LSTR=''
还得加上楼上的
declare @id int,@title char(10),@str char(10),@lstr char(100)
set @lstr=''--要初值
set @title='';
set @id=''
set @str='';
declare my_cursor cursor for
select employeeid,titleofcourtesy
from employees
Open my_cursor
fetch my_cursor into @id,@title
while @@fetch_status=0
begin
set @lstr = @lstr+@title
print @lstr
fetch my_cursor into @id,@title
end
print @title
close my_cursor
deallocate my_cursor
declare @id int,@title char(10),@str char(10)
declare @lstr varchar(max) -- 变换类型
declare my_cursor cursor for
select employeeid,titleofcourtesy
from employees
Open my_cursor
fetch my_cursor into @id,@title
while @@fetch_status=0
begin
set @lstr = isnull(@lstr, '') + @title --转化NULL值
print @lstr
fetch next from my_cursor into @id,@title
end
print @title
close my_cursor
deallocate my_cursor
declare my_cursor cursor for
select employeeid,titleofcourtesy
from employees
Open my_cursor
fetch my_cursor into @id,@title
set @lstr=''
while @@fetch_status=0
begin
set @lstr = @lstr+@title
print @lstr
fetch my_cursor into @id,@title
end
print @lstr
close my_cursor
deallocate my_cursor
/*
Ms.
Ms. Dr.
Ms. Dr. Ms.
Ms. Dr. Ms. Mrs.
Ms. Dr. Ms. Mrs. Mr.
Ms. Dr. Ms. Mrs. Mr. Mr.
Ms. Dr. Ms. Mrs. Mr. Mr. Mr.
Ms. Dr. Ms. Mrs. Mr. Mr. Mr. Ms.
Ms. Dr. Ms. Mrs. Mr. Mr. Mr. Ms. Ms.
Ms. Dr. Ms. Mrs. Mr. Mr. Mr. Ms. Ms
*/
declare my_cursor cursor for
select employeeid,titleofcourtesy
from employees
Open my_cursor
fetch my_cursor into @id,@title
set @lstr=''
while @@fetch_status=0
begin
set @lstr = @lstr+@title
print @lstr
fetch my_cursor into @id,@title
end
print @title
close my_cursor
deallocate my_cursor
/*
Ms.
Ms. Dr.
Ms. Dr. Ms.
Ms. Dr. Ms. Mrs.
Ms. Dr. Ms. Mrs. Mr.
Ms. Dr. Ms. Mrs. Mr. Mr.
Ms. Dr. Ms. Mrs. Mr. Mr. Mr.
Ms. Dr. Ms. Mrs. Mr. Mr. Mr. Ms.
Ms. Dr. Ms. Mrs. Mr. Mr. Mr. Ms. Ms.
Ms. */