Hi Group,
i am trying to use the DatePart function on my SQL2000 database. I have a
table called visitors with a field called DateTimeEntranc e which is filled
everytime a visitor enters the site. I am trying to build a stat page where
i display the total amount of visitors per day, week, month, year and i
can't seem to get the syntax correct.
I get an error with the following code:
sql = "SELECT * FROM tblVisitors WHERE (DatePart("yyyy ",
[datetimeentranc e])) = (DatePart("yyyy ", date()))"
can anyone help me with the correct syntax?
thanks in advance for any help received
David 3 6296
sql = "SELECT * FROM tblVisitors WHERE (DatePart("yyyy ",
[datetimeentranc e])) = (DatePart("yyyy ", date()))"
1) You didn't escape your quotes (double them up)
2) DatePart uses a different format than VB, refer to BOL
sql="SELECT [columnX], [columnY] FROM tblVisitors WHERE
DATEPART(yyyy,[datetimeentranc e])=DATEPART(yyyy ,GETDATE())"
I think that's right
"David" <db********@blu eyonder.co.uk> wrote in message
news:uK******** ******@TK2MSFTN GP11.phx.gbl... Hi Group, i am trying to use the DatePart function on my SQL2000 database. I have a table called visitors with a field called DateTimeEntranc e which is filled everytime a visitor enters the site. I am trying to build a stat page
where i display the total amount of visitors per day, week, month, year and i can't seem to get the syntax correct. I get an error with the following code:
sql = "SELECT * FROM tblVisitors WHERE (DatePart("yyyy ", [datetimeentranc e])) = (DatePart("yyyy ", date()))"
can anyone help me with the correct syntax?
thanks in advance for any help received
David
Hi,
thanks Tom for your help. I still don't have it working. You said i didn't
escape my quotes(double them up) but in your example you have none, did i
miss something here?
You said DatePart uses a different format, which is?? and what is BOL?
sorry if the answer is there, i maybe just don't understand your answer.
thanks
David
"Tom B" <sh*****@hotmai l.com> wrote in message
news:Oz******** ********@TK2MSF TNGP12.phx.gbl. .. sql = "SELECT * FROM tblVisitors WHERE (DatePart("yyyy ", [datetimeentranc e])) = (DatePart("yyyy ", date()))"
1) You didn't escape your quotes (double them up) 2) DatePart uses a different format than VB, refer to BOL sql="SELECT [columnX], [columnY] FROM tblVisitors WHERE DATEPART(yyyy,[datetimeentranc e])=DATEPART(yyyy ,GETDATE())"
I think that's right
"David" <db********@blu eyonder.co.uk> wrote in message news:uK******** ******@TK2MSFTN GP11.phx.gbl... Hi Group, i am trying to use the DatePart function on my SQL2000 database. I have
a table called visitors with a field called DateTimeEntranc e which is
filled everytime a visitor enters the site. I am trying to build a stat page where i display the total amount of visitors per day, week, month, year and i can't seem to get the syntax correct. I get an error with the following code:
sql = "SELECT * FROM tblVisitors WHERE (DatePart("yyyy ", [datetimeentranc e])) = (DatePart("yyyy ", date()))"
can anyone help me with the correct syntax?
thanks in advance for any help received
David
I wasn't very clear...sorry.
My suggestion
would produce the following sql statement being sent to the server
SELECT [columnX], [columnY] FROM tblVisitors WHERE
DATEPART(yyyy,[datetimeentranc e])=DATEPART(yyyy ,GETDATE())
1)I just mentioned the double quote thing to clear up what your errors would
be. If you want to include a quote in a string you have to escape it. For
example:
Dim aString
aString="Then he said ""hello there"""
would store
The he said "hello there"
in the aString variable.
2) The DatePart format that you used is for vb/vbscript
DatePart("yyyy" , date())
but you wanted to use the T-SQL version which is
DatePart(yyyy, GetDate())
3) Books OnLine (BOL) should be installed on your SQL Server. It's also
available for download separately at www.microsoft.com/sql
"David" <db********@blu eyonder.co.uk> wrote in message
news:O3******** ******@TK2MSFTN GP09.phx.gbl... Hi, thanks Tom for your help. I still don't have it working. You said i
didn't escape my quotes(double them up) but in your example you have none, did i miss something here? You said DatePart uses a different format, which is?? and what is BOL?
sorry if the answer is there, i maybe just don't understand your answer.
thanks David
"Tom B" <sh*****@hotmai l.com> wrote in message news:Oz******** ********@TK2MSF TNGP12.phx.gbl. .. sql = "SELECT * FROM tblVisitors WHERE (DatePart("yyyy ", [datetimeentranc e])) = (DatePart("yyyy ", date()))"
1) You didn't escape your quotes (double them up) 2) DatePart uses a different format than VB, refer to BOL sql="SELECT [columnX], [columnY] FROM tblVisitors WHERE DATEPART(yyyy,[datetimeentranc e])=DATEPART(yyyy ,GETDATE())"
I think that's right
"David" <db********@blu eyonder.co.uk> wrote in message news:uK******** ******@TK2MSFTN GP11.phx.gbl... Hi Group, i am trying to use the DatePart function on my SQL2000 database. I
have a table called visitors with a field called DateTimeEntranc e which is filled everytime a visitor enters the site. I am trying to build a stat page where i display the total amount of visitors per day, week, month, year and
i can't seem to get the syntax correct. I get an error with the following code:
sql = "SELECT * FROM tblVisitors WHERE (DatePart("yyyy ", [datetimeentranc e])) = (DatePart("yyyy ", date()))"
can anyone help me with the correct syntax?
thanks in advance for any help received
David
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: sdowney717 |
last post by:
The field itemdate is a datetime field in sqlserver2000 DB
This works fine:
Select Id From BookData Where (MONTH(itemdate) = '01') and
(DAY(itemdate) = '02') and (YEAR(itemdate) = '2005') order by
TitleDuplicate
This does not work:
Select Id From BookData Where (MONTH(itemdate) = '01') and
(DAY(itemdate) = '02') and (YEAR(itemdate) = '2005') and (datepart(Hh,
|
by: Alicia |
last post by:
Hi, I am trying to group by week and do a count of my data in between
the dates. In Microsoft Access.
Something similar to
Before:
Date Count
--------- ---------
10/02/04 2
|
by: sean |
last post by:
Hi All,
I have one table TABLE1 in access2k on machine PC1, that has one
column named DO_DATE with "Date/Time" data type. Two other machines
PC2 and PC3 also running access2k. Each PC has its own data entry
form, and each form would execute the following insert query
independently:
INSERT INTO TABLE1 (DO_DATE, ... )
SELECT DatePart("m",.) & "/" &
|
by: Aaran76 |
last post by:
I am creating a booking system in ASP.Net with VB and a MSSQL backend.
I am having problems knowing where to begin with a particular part of the
system. Bookings can only be made in weekly multiples from Saturday to
Saturday.
The only way I can think of to do it is by manually adding the weeks into a
table in the DB, but this will obviously mean that I will have to routinely
update this table.
|
by: troddy |
last post by:
I am using the DatePart funtion in a query to extract the day, month
and year in separate fields in a query. The function works fine but I
am only getting a number for the month even if the field type is a long
date and the month is stored in the table. I tried the following to try
and get the name of the month to work.
DateTest: Format(DatePart("m",),"mmmm")
The DateAffirmed field had a date stored of 16/03/2006.
| |
by: le0 |
last post by:
Hello guys,
Is there anything wrong with my code (see below) bcoz when 10p-6a shift my
browser returns the error cannot be a zero-length string. Im wondering why,
bcoz the 2 other shift works perfectly.
<%
'Shift: 6a-2p
if DatePart("h", Now()) 5 And DatePart("h", Now()) < 14 then
ShiftID = "A"
|
by: tasmontique |
last post by:
I have an access table that outputs to excel using a query . However what I am trying to do is under the arrival date column specify a criteria based on the Datepart function that only displays output based on specific day of week.
I want query to check the stored date in the arrival column and based on that date that is examined by the date part function only return rows based on day of week .Here is my sql.
SELECT...
|
by: devagupt |
last post by:
Hello ,
I have a query which adds all the downtime for a given week and displays it. All i have to do is , is to type the week number and it shows be the data. However we have rolled into the new yr ( 2008). I would like it to display information for 2nd week in Jan 2008 for me. When i enter 2( 2nd week), it displays the 2nd week in 2007.
Please help.
Thanks in advance
Present CODE***
Expr1: DatePart("ww",!)
|
by: grabit |
last post by:
Hi Peoples
I am having probs with the datepart function with a query.What i want is to get all listings made in any month in any year ie May 2007
i have 2 drop down boxes to select the listedmonth and listedyear on the refering page
I need to be able to retrieve this so i can send out renewals to those listings for another year.
I am using this query
<cfquery name="getrenew" datasource="#dsn#">
SELECT datelisted
FROM listings
WHERE...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |