Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Converting Code from Access to SQL -- Specifically DateSerial

Posted on 2006-10-26
2
Medium Priority
?
302 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 93

Accepted Solution

by:
Patrick Matthews earned 1000 total points
ID: 17813740
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
ID: 17813746
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
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…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

783 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