I am trying get the values using SP.The query is below.
create proc [dbo].[GetOrdersByUserID11]
(
@UserID int
)
as
begin
declare @status varchar(1000)
set @status=' 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 '
set @status=@status+' Join Tbl_Orders c ON c.UserID = '+convert(varchar(10),@UserID)+''
set @status=@status+'Order By CategoryText, CourseTitle '
print @status
exec(@status)
select * from #myCourses1
end
This is message from my query when run my SP[[dbo].[GetOrdersByUserID11] 5085 ]:
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 = 5085
(99 row(s) affected)
i am getting message 99 rows affected but in my results getting only header with 0(zero) columns.
Plz do help me for getting values.
Thanks in advance.
The temp table you create is only within scope of the EXEC statements, not the outer query.
Select within the statement:
Or create the temp table first (so create/select are within the same scope).