Here is my mssql code snippet
Select
Sum((Case
When (me.status in ('CLOSED','VOID') and
Convert(DATE,me.end_dt)=CONVERT(DATE,GETDATE()))
Then 1 else 0
end)) as completed,
Sum((Case
When datediff
( hh, cast (CONVERT (DATE, GETDATE()) as varchar)+' '+ '00:00:00.000', me.due_dt)
between 12 and 24 and me.status not in ('CLOSED','VOID')
Then 1 else 0
end)) as Count_12_to_24
from pvr_svc me with(nolock)
For the first chunk of query this is what i have tried so far.
expr = func.sum(case([(and_(pvr_svc.status.in_(['CLOSED','VOID']),
(func.convert(DATE, pvr_svc.end_dt)== func.convert(DATE, func.current_date()))
),1)],else_=0)).label('com')
session.query(expr).scalar()
But i get an error saying.
****** NotImplementedError: Don't know how to literal-quote value (class 'sqlalchemy.types.DATE')***
I have few questions here,
Q1. How do i convert the datetime column values (in the above case me.end_dt) to DATE type?
Q2. What is the equivalent of the GETDATE() in sqlalchemy? (i have tried func.current_date(), func.now())
Q3. What is the right way of implementing the last chunk of the mssql code snippet?
I have went through the sqlalchemy doc, found some information on the stackoverflow, below are the links,