December 16, 2010 at 1:47 am
Hello everyone,
My trouble is that I have objects stored as date type, not datetime. So that I can identify ex
Column name | Type
Patient_code int
Patient_name varchar(50)
Invoice_code int
Date_Visit
December 16, 2010 at 2:27 am
I don't want to come off as mean, but your problem is that you fail to communicate what your problem is.
If your object is in fact the Java "Date" class, that actually contains both date and time, so no problems there. If it's the Java SQL "Date" class you need to change that.
December 16, 2010 at 2:31 am
IIUC , you have a datetime datatype , and you wish to remove the time portion , correct ?
You cant , its intrinsic to the datatype, Please see this page for a full explanation and your options.
December 16, 2010 at 6:56 pm
Based on code from the other thread (provided by Kingston, with much thanks), try this:
DECLARE @tblTemp TABLE
(
Patient_Code int,
Patient_Name varchar(50),
Invoice_Code int,
Date_Created date,
Date_Visit date
)
INSERT @tblTemp
SELECT 20, 'David', 2, '2010-11-15', '2010-12-15' UNION ALL
SELECT 21, 'Anna', 3, '2010-12-15', '2010-12-15' UNION ALL
SELECT 21, 'Anna', 4, '2010-12-15', '2010-12-15' UNION ALL
SELECT 21, 'Anna', 5, '2010-12-15', '2010-12-16' UNION ALL
SELECT 22, 'Peter', 6, '2010-12-20', '2010-12-20';
with Patient_Recs as (
SELECT
Patient_Code,
Patient_Name,
Invoice_Code,
Date_Created,
Date_Visit,
ROW_NUMBER() over (partition by Patient_Code, Date_Visit order by Invoice_Code) as RowNum
from
@tblTemp
)
select
Patient_Code,
Patient_Name,
Invoice_Code,
Date_Created,
Date_Visit,
case when RowNum = 1 then 'New' else 'Return' end as Status
from
Patient_Recs;
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply