下面是我写的。 但是,在试图处理这一争执时,正发现这一错误:
There is already an object named #myCourses1 in the database.
因此,这在另外两处 lo。 并且
create proc [dbo].[GetOrdersByUserIDwithSubscription]
(
@UserID int
)
as
begin
declare @status varchar(500)
declare @substatus char(2)
select @substatus=Subscribe_status from tbl_user where userid=@userid
print @substatus
if @substatus= N
BEGIN
select a.*, b.CategoryText, Cast( as Varchar(10)) as SectionsViewed, PurchasedDate as dateadded into #myCourses1 from dbo.Tbl_CourseInformations a JOIN Tbl_Categories b ON a.AssignCategory = b.CategoryID
Join Tbl_Orders c ON c.UserID = @UserID and c.CourseID = a.CourseID and c.courseprice<> subscriber
Order By CategoryText, CourseTitle
END
else if @substatus=
BEGIN
select a.*, b.CategoryText, Cast( as Varchar(10)) as SectionsViewed, PurchasedDate as dateadded into #myCourses1 from dbo.Tbl_CourseInformations a JOIN Tbl_Categories b ON a.AssignCategory = b.CategoryID
Join Tbl_Orders c ON c.UserID = @UserID and c.CourseID = a.CourseID and c.courseprice<> subscriber
Order By CategoryText, CourseTitle
END
else if @substatus= Y
BEGIN
select a.*, b.CategoryText, Cast( as Varchar(10)) as SectionsViewed, PurchasedDate as dateadded into #myCourses1 from dbo.Tbl_CourseInformations a JOIN Tbl_Categories b ON a.AssignCategory = b.CategoryID
Join Tbl_Orders c ON c.UserID = @UserID and c.CourseID = a.CourseID
Order By CategoryText, CourseTitle
END