drop procedure viewbook
go
create procedure viewbook
@id3 int
as
if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempTable'))
drop table #tempTable
create Table #tempTable
(
ID int IDENTITY PRIMARY KEY,
bookId int,
bookName varchar(50)
)
declare book_cursor cursor for
select userId from borrowTable where bookid=@id3
declare @name varchar(50)
open book_cursor
fetch next from book_cursor into @name
while @@fetch_status=0
begin
fetch next from book_cursor into @name
insert into #tempTable(bookId,bookName)
select [Id],bookName from bookTable where [id]<>1 and [id] in
(select bookId from borrowTable where userId=@name)
end
close book_cursor
deallocate book_cursor
select distinct top 3 bookname from #tempTable
+++++++++++++++++++
if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempTable'))--判断临时表是否 存在
drop table #tempTable
go
create Table #tempTable
(
ID int IDENTITY PRIMARY KEY,
bookId int,
bookName varchar(50)
)
go
declare @id3 int
set @id3=1
declare book_cursor cursor for
select userId from borrowTable where bookid=@id3
declare @name varchar(50)
open book_cursor
fetch next from book_cursor
while @@fetch_status=0
begin
fetch next from book_cursor into @name
insert into #tempTable(bookId,bookName)
select [Id],bookName from bookTable where [id]<>1 and [id] in
(select bookId from borrowTable where userId=@name)
end
close book_cursor
deallocate book_cursor
go
select distinct top 3 bookname from #tempTable
(正确)
-------------------------
drop table #tempTable
go
create Table #tempTable
(
bookName varchar(50)
)
go
declare book_cursor cursor for
select distinct userId from borrowTable where bookid=1
declare @name varchar(50)
open book_cursor
fetch next from book_cursor
while @@fetch_status=0
begin
fetch next from book_cursor into @name
select distinct @name
insert into #tempTable select (@name)
end
close book_cursor
deallocate book_cursor
select distinct bookName from #tempTable
++++++++++++++++++++++++++++++++++++++++
create Table #tempTable
(
ID int IDENTITY PRIMARY KEY,
bookId int,
bookName varchar(50)
)
go
declare book_cursor cursor for
select userId from borrowTable where bookid=1
declare @name varchar(50)
open book_cursor
fetch next from book_cursor
while @@fetch_status=0
begin
fetch next from book_cursor into @name
insert into #tempTable(bookId,bookName)
select [Id],bookName from bookTable where [id]<>1 and [id] in
(select bookId from borrowTable where userId=@name)
end
close book_cursor
deallocate book_cursor
select * from #tempTable
declare T cursor for select DisplayItemOriginalText from tbl_displayitem where DisplayItemOriginalText like '%display order%'
declare @displaytext varchar(1000)
declare @tempvalue varchar(1000)
open T
fetch next from T
while @@fetch_status =0
begin
fetch next from T into @displaytext
set @tempvalue = @displaytext
set @displaytext =replace(@displaytext,'Display Order','sequence')
update tbl_displayitem set DisplayItemOriginalText=@displaytext where DisplayItemOriginalText=@tempvalue
fetch next from T
end
close T
deallocate T
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++