1
If lastdrugpickup datatype is date then wondering how you have saved date in dd/mm/yyyy format
if you run below query it will not allow to run, because it will only store date in yyyy-mm-dd format
declare @date date
set @date='21/01/2016'
select @date
and for sorting i guess sql server assumes lastdrugpickup as varchar column and not able to sort it.
1
SELECT * FROM `tbl_radet` ORDER BY `tbl_radet`.`LastDrugPickup` DESC LIMIT 1
0
SELECT * FROM TableName WHERE id=(SELECT max(id) FROM TableName);
0
hello abraham,
you use query like this ..
select top 1 * from tbl_RADET where ptn_pk ='4020' order by Cast(Convert(nvarchar(30),lastdrugpickup,112) as int) desc
0
WITH Res
AS (SELECT
ROW_NUMBER() OVER (
PARTITION BY tbl_RADET.PatientID ORDER BY LastDrugDate DESC
) AS Row
,Ptn_pk
,PatientID
,ARTStartDate
,LastDrugDate
FROM tbl_RADET where ptn_pk ='4020')
SELECT
*
FROM Res
WHERE ROW = 1
0
Many thanks Manish Kumar, the data type of lastdrugpickup is date
0
Many Thanks Khaja Moizuddin,
I have tried
SELECT TOP 1 * FROM tbl_RADET ORDER BY lastdrugpickup DESC
this just return the last row in the table, but not the most current LastDrugPickup date.
I also tried
select * from tbl_RADET where ptn_pk ='4020' order by 1 desc which give the same result as Select * from tbl_RADET where ptn_pk = '4020'.
so far all these solution is not giving expected result. i will appreciate any solution
0
what is the data type of column lastdrugpickup
0
SELECT TOP 1 * FROM tbl_RADET ORDER BY lastdrugpickup DESC
where ptn_pk ='4020' is optional
0
select * from tbl_RADET where ptn_pk ='4020' order by 1 desc