Navjot Angra

Navjot Angra

  • NA
  • 489
  • 242.5k

How can i do sorting in sql?

Jan 16 2019 7:09 AM
Suppose i have following coloumn
AppointDateTime 
01-15-2019 21:14:12
01-16-2019 12:05:13
01-16-2019 12:55:47
01-16-2019 17:25:00
01-16-2019 18:19:20
01-17-2019 05:18:30
 
Now I want to soterd data according to date and as well as time 
 

01-16-2019 12:05:13
01-16-2019 12:55:47
01-16-2019 17:25:00
01-16-2019 18:19:20
01-17-2019 05:18:30
01-15-2019 21:14:12 
 
So how can i do this
Following is my query
 
USE [docprimenew]
GO
/****** Object: StoredProcedure [BMS].[GetAgentDashboardDetails] Script Date: 01-16-2019 15:47:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROC [BMS].[GetAgentDashboardDetails]
(
@ProductID Smallint = null,
@Leads [BMS].[LeadTable] READONLY
)
AS
BEGIN
SET NOCOUNT ON
SET DEADLOCK_PRIORITY LOW
Select * from (
SELECT Distinct
LD.LeadID,
LD.Name,
LD.EmailId,
--STUFF(LD.MobileNo, 1, 6,'******') AS MobileNo,
cast (LD.MobileNo as varchar(50)) AS MobileNo,
LD.CustomerID,
LD.LeadSource,(cast(isnull(CCBD.CallBackDate,'') as datetime)+isnull(CCBD.StartTime,'')) as CallBackDate,
LD.CreatedOn,
LD.UpdatedOn as 'StatusDate',
ZC.City,'Consumer' as ProductName,
Ld.ProductID ,
bd.BookingDateTime as OffercreatedOn,
0 as OfferNumber,
SM.StatusName,
Bd.AppointmentDatetime as AppointmentdateTime,
0 as CustIdentityID
-- ,cast([BMS].[CheckTwoDatesDifference](Bd.DocPrimeBookingID) as varchar(100)) as Time
FROM @Leads AS L
INNER JOIN prime.AppointmentDetails BDWITH(NOLOCK) ON L.LeadID=BD.LEADID and bd.IsActive=1
INNER JOIN CRM.Leaddetails LDWITH(NOLOCK) ON L.LeadID=LD.LeadId
left join BMS.CustomerCallBackDetails CCBD WITH(NOLOCK) ON L.LeadID=CCBD.LeadId and CCBD.IsActive=1
INNER JOIN CRM.LeadStatus LSWITH(NOLOCK) ON L.LeadID = LS.LeadID AND LS.IsLastStatus=1
INNER JOIN CRM.Statusmaster SMWITH(NOLOCK) ON SM.StatusID = LS.StatusID and SM.IsActive=1
LEFT JOIN import.zonecities ZCWITH(NOLOCK) ON ZC.CityID=LD.CityID
)
--as a ORDER BY OffercreatedOn DESC
as a ORDER BY AppointmentdateTime
END

Answers (8)