Solved

Converting Code from Access to SQL -- Specifically DateSerial

Posted on 2006-10-26
2
298 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 250 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mask value when navigating 5 21
dat and idx extensions 11 43
Access Schema Relationship Design for Multi-Level Chart of Accounts 17 82
TDE for SQL Web Edition 1 42
CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
Read about achieving the basic levels of HRIS security in the workplace.
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…

751 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