Thursday, February 4, 2010

HOW TO USe temporary TABLE

set ANSI_NULLS OFF
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[360LMS_SearchUserPaymentDetail]
@username nvarchar(50)
AS


Declare @temppayment TABLE
(srno smallint IDENTITY Primary Key,
UserID int,
fullname nvarchar(50),
CollegeName nvarchar(50),
Faculty nvarchar(50),
CourseTitle nvarchar(50),
TotalAmountPaid int,
balance int,
duration nvarchar(100),
IsActive int,
RoleId int,
UserName nvarchar(50)
)

INSERT INTO @temppayment
SELECT ucp.UserID,
u.FirstName+' '+u.LastName as fullname,
u.CollegeName,
u.Faculty,
'Certified Course In Information Security' as CourseTitle,
ucp.TotalAmountPaid,
(12500 - ucp.TotalAmountPaid) as balance,
ucp.Duration,
u.IsActive,
u.RoleId,
u.UserName
FROM [360LMS_Users] as u,
[360LMS_UserCoursePayment] As ucp
WHERE
u.UserID=ucp.UserID and u.RoleId='3' and u.DeleteFlag <> 'True'
and (u.FirstName like '%'+@username+'%' or u.FirstName like '%'+@username+'%' )
and ucp.TotalAmountPaid = (SELECT MAX(TotalAmountPaid) FROM [360LMS_UserCoursePayment] WHERE UserID = ucp.UserID )

select * from @temppayment;

No comments:

Post a Comment