Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created below stored procedure to sort data in descending order of enquiry date but the data isn't getting sorted...
Please help me... Thanks in advance
SQL
ALTER Procedure [GetEnquiriesForPurchase]
	@PageIndex INT = 1
	,@PageSize INT = 10
	,@RecordCount INT OUTPUT
	--,@IsProcess int
	,@EmpId int=null
as
Begin
	SET NOCOUNT ON;
	SELECT distinct(Enq.EnquiryId) ,
		--ROW_NUMBER() OVER
		DENSE_RANK() OVER
		(
			--PARTITION BY Enq.EnquiryId 
			ORDER BY Enq.EnquiryDate DESC
		)AS RowNumber,
		Enq.enquirydate, emp.FirstName +' '+emp.LastName as EmployeeName
		,emp.Emailid
		,Enq.[Status]
		,Enq.[ActionRequiredBy]
		, Cust.Name
		,Cust.Designation 
		,Enq.Isprocess
		--,PEND.PurchasePersonId
		--,emp.FirstName +' '+emp.LastName as PurchaseHandler
	INTO #Results 
	from Enquiries Enq 
	inner join employees emp on Enq.SalesPersonId=emp.Id 
	--inner join PurchaseEnquiryNewDetails PEND on PEND.PurchasePersonId =emp.Id and PEND.enquiryId=Enq.enquiryId
	inner join Enquirydetails enqdet on enqdet.EnquiryId=enq.EnquiryId
	inner join Customers cust on Enq.CustomerId=Cust.Id and enqdet.manufactureCode in ( select mfg.manufactureCode from manufacturers mfg
			inner join aspnet_Roles asr on asr.RoleName=mfg.Name
			inner join aspnet_UsersInRoles aur on aur.RoleId= asr.RoleId
			inner join employees emp1 on emp1.loginid= aur.UserId and emp1.Id=@EmpId)
	ORDER BY Enq.EnquiryDate DESC

	SELECT @RecordCount = COUNT(*)
	FROM #Results

	SELECT * FROM #Results
	WHERE RowNumber BETWEEN(@PageIndex -1) * @PageSize + 1 AND(((@PageIndex -1) * @PageSize + 1) + @PageSize) - 1

	DROP TABLE #Results
End 
Posted
Updated 1-Sep-15 1:39am
v4
Comments
Maciej Los 1-Sep-15 7:39am    
We can't read in your mind or direct from your screen. Please, be more specific and provide more details, for example input data and expected output.
CHill60 1-Sep-15 7:40am    
To sort data in SQL use ORDER BY enquirydate DESC on your final query
Herman<T>.Instance 1-Sep-15 7:55am    
Set it as an answer!
CHill60 1-Sep-15 7:59am    
Actually I will :)

To sort data in SQL use ORDER BY enquirydate DESC on your final query
 
Share this answer
 
Comments
Herman<T>.Instance 1-Sep-15 8:26am    
+5
Your can write your query like......

SQL
Select * from Enquiries ORDER BY enquirydate DESC
 
Share this answer
 
Comments
CHill60 1-Sep-15 8:29am    
It's the results from #Results that the OP needs to be in order

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900