Solved

Converting Code from Access to SQL -- Specifically DateSerial

Posted on 2006-10-26
2
291 Views
Last Modified: 2012-05-05
I am having trouble converting a bit of Access code that appears in my select statement as:

SELECT DateSerial(Year(dbo_TPB105_CHARGE_DETAIL!chg_srv_ts),Month(dbo_TPB105_CHARGE_DETAIL!chg_srv_ts),Day
(dbo_TPB105_CHARGE_DETAIL!chg_srv_ts)) AS cntdate

And also in the WHERE statement:

WHERE (((DateSerial(Year([dbo_TPB105_CHARGE_DETAIL]![chg_srv_ts]),Month([dbo_TPB105_CHARGE_DETAIL]![chg_srv_ts]),Day([dbo_TPB105_CHARGE_DETAIL]![chg_srv_ts])))>Date()-2 And (DateSerial(Year([dbo_TPB105_CHARGE_DETAIL]![chg_srv_ts]),Month([dbo_TPB105_CHARGE_DETAIL]![chg_srv_ts]),Day([dbo_TPB105_CHARGE_DETAIL]![chg_srv_ts])))<Date()))

What I am trying to accomplish is to obtain the records where the chg_srv_ts is yesterday (between 12:00 a.m. and 11:59 p.m.)

Can anyone help?

Thanks!



0
Comment
Question by:PHS_IT
2 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 250 total points
Comment Utility
Hi PHS_IT,

SELECT CONVERT(datetime, CONVERT(varchar(12), dbo.TPB105_CHARGE_DETAIL.chg_srv_ts, 106)) AS cntdate

...

WHERE CONVERT(datetime, CONVERT(varchar(12), dbo.TPB105_CHARGE_DETAIL.chg_srv_ts, 106)) =
    (CONVERT(datetime, CONVERT(varchar(12), GETDATE(), 106)) - 1)

Regards,

Patrick
0
 
LVL 29

Expert Comment

by:Nightman
Comment Utility
SELECT CAST(CONVERT(nvarchar(10), chg_srv_ts,112) as datetime)  as cntdate
in the WHERE statement

WHERE chg_srv_ts BETWEEN dateadd(day,-1 ,CAST(CONVERT(nvarchar(10),getdate(),112) as datetime)) AND CAST(CONVERT(nvarchar(10),getdate(),112) as datetime)

the where will always return yesterdays data
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction: I have seen many questions on EE and elsewhere, asking about how to find either gaps in lists of numbers (id field, usually) ranges of values or dates overlapping date ranges combined date ranges I thought it would be a good …
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now