472,989 Members | 3,058 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,989 software developers and data experts.

Syntax error in Create Table statement? Why

Does anyone know why I am getting a "Syntax error in Create Table
statement". I am using Microsoft Access SQL View to enter it. Any
other problems I may run into?

CREATE TABLE weeks
(
weekstart datetime not null primary key,
weekend datetime not null
)

insert into weeks(weekstart, weekend) values (#09/30/04#, #10/07/04#)
insert into weeks(weekstart, weekend) values (#10/07/04#, #10/14/04#)
insert into weeks(weekstart, weekend) values (#10/14/04#, #10/21/04#)
insert into weeks(weekstart, weekend) values (#10/21/04#, #10/28/04#)
insert into weeks(weekstart, weekend) values (#10/28/04#, #11/04/04#)

select w.weekstart, sum(a.[Count]) as newCount
from weeks as w
left outer join alicia as a on w.weekstart > a.[Date]
and w.weekend <= a.[Date]
group by w.weekstart
Nov 13 '05 #1
2 13818
rkc

"Alicia" <al******@hotmail.com> wrote in message
news:d3**************************@posting.google.c om...
Does anyone know why I am getting a "Syntax error in Create Table
statement". I am using Microsoft Access SQL View to enter it. Any
other problems I may run into?


The following always works for me.

CREATE TABLE weeks
(
weekstart datetime not null,
weekend datetime not null,
CONSTRAINT pkWeeks PRIMARY KEY (weekstart)
)
Nov 13 '05 #2
Hi Alicia,

IMHO, It appears that you are missing the CONSTRAINT clause while attemping
to create your Primary Key field.

Try:
CREATE TABLE Weeks (Weekstart datetime Not Null CONSTRAINT Weekstart Primary
Key, Weekend DateTime Not Null);

--------------------------------------------------------------
I'm a little confused by the rest of the code / SQL that follows.
Do segments of it run in seperate processes or procedures? I can't see how
it could possibly run continuously...
Here is some code that I created messing around with this a little this
afternoon.
I think I have succeeded in combining the first 2 operations ... (make the
table and populate it with data in the pattern that I noticed in your
sample.)

Is this what you have in mind?
*********************************************
Private Sub Command0_Click()

'IsTableQuery function from
http://support.microsoft.com/default...b;en-us;113549
'Checks to see if the table named "Weeks" already exists.

Dim MyDB As DAO.Database
Set MyDB = CurrentDb

Dim MySQL As String

Dim i As Integer
Dim intRecords As Integer
intRecords = InputBox("How many records would you like to create?", "Create
Records", 1)

Dim dteStart As Date
Dim dteEnd As Date
dteStart = InputBox("Enter start date ... in mm/dd/yyyy format.", "Please
supply a start date", Format(Date, "mm\/dd\/yyyy"))
'This InputBox prompts you for a date, and uses the current system date as a
default.

If Not IsTableQuery("", "Weeks") Then
'The IsTableQuery function checks to see if the table already exists.
'If it does, it skips this portion of the code ... which prevents an error.

MySQL = ""
MySQL = MySQL & "CREATE TABLE Weeks "
MySQL = MySQL & "(Weekstart datetime Not Null CONSTRAINT Weekstart
Primary Key,"
MySQL = MySQL & " Weekend DateTime Not Null);"
'Debug.Print MySQL ' I used this to check the SQL output, and made sure
that it works

MyDB.Execute MySQL, dbFailOnError
End If

If IsDate(dteStart) Then
'According to the pattern that you posted, the
'"weekend" value was always 7 days after "weekstart"
dteEnd = DateAdd("d", 7, dteStart)
End If

For i = 0 To intRecords - 1
'This For / Next loop inserts the records, counts how many have been
created so far,
'increments the "weekstart" / "weekend" values,
'and stops when the count reaches the specified number

'insert into weeks(weekstart, weekend) values (#09/30/04#, #10/07/04#)
MySQL = ""
MySQL = MySQL & "INSERT INTO Weeks (weekstart, weekend) values "
MySQL = MySQL & "(#"
MySQL = MySQL & dteStart
MySQL = MySQL & "#, #"
MySQL = MySQL & dteEnd
MySQL = MySQL & "#);"

MyDB.Execute MySQL, dbFailOnError
'Also according to the pattern that you posted, the
'new "weekstart" value was always the same as the
'last record's "weekend" value, so ...

dteStart = dteEnd
dteEnd = DateAdd("d", 7, dteEnd)

Next i

Set MyDB = Nothing
End Sub

***********************************************
--
HTH,
Don
=============================
Use My*****@Telus.Net for e-mail
Disclaimer:
Professional PartsPerson
Amateur Database Programmer {:o)

I'm an Access97 user, so all posted code
samples are also Access97- based
unless otherwise noted.

Do Until SinksIn = True
File/Save, <slam fingers in desk drawer>
Loop

================================

"Alicia" <al******@hotmail.com> wrote in message
news:d3**************************@posting.google.c om...
Does anyone know why I am getting a "Syntax error in Create Table
statement". I am using Microsoft Access SQL View to enter it. Any
other problems I may run into?

CREATE TABLE weeks
(
weekstart datetime not null primary key,
weekend datetime not null
)

insert into weeks(weekstart, weekend) values (#09/30/04#, #10/07/04#)
insert into weeks(weekstart, weekend) values (#10/07/04#, #10/14/04#)
insert into weeks(weekstart, weekend) values (#10/14/04#, #10/21/04#)
insert into weeks(weekstart, weekend) values (#10/21/04#, #10/28/04#)
insert into weeks(weekstart, weekend) values (#10/28/04#, #11/04/04#)

select w.weekstart, sum(a.[Count]) as newCount
from weeks as w
left outer join alicia as a on w.weekstart > a.[Date]
and w.weekend <= a.[Date]
group by w.weekstart

Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Robert Mark Bram | last post by:
Hi All! I have the following two methods in an asp/jscript page - my problem is that without the update statement there is no error, but with the update statement I get the following error: ...
4
by: Thomas Jerkins | last post by:
When I write a create table SQL statement I want to add some information about the column heading of each column. How does the exact syntax for the create table look like (which includes this column...
12
by: ColinWard | last post by:
Hi. I am trying to run the following code when the user clicks a button, but I am getting a syntax error in the SQL. I have a feeling it has to do with brackets. Can anyone help? here is the...
7
by: kosta | last post by:
hello! one of my forms communicates with a database, and is supposed to add a row to a table using an Insert statement... however, I get a 'oledb - syntax error' exception... I have double...
1
by: amitbadgi | last post by:
HI i am getting the foll error while conv an asp application to asp.net Exception Details: System.Runtime.InteropServices.COMException: Syntax error in UPDATE statement. Source Error: Line...
4
by: Jan | last post by:
Have an SQL create/import script. Running this on SQL would make it create a table with some values. Can Access2003 somehow use such and SQL script? I went into SQL query view to try it out, but...
0
by: luckyger_07 | last post by:
Hi, The following code generates an error and I am not sure why. The error says syntax error in UPDATE statement. Anyone have any ideas? Your help will greatly appreciated. Dim...
8
by: Stephen Plotnick | last post by:
I have three forms and update one table in an Access DB with sucess in one form. In the other two forms I'm trying to do an update to a different table in the Access DB. The error I'm getting...
4
by: nanabuch | last post by:
Hello, I am new to this forum, and I am a newbit in Oracle, I do have a background in MS Access, VBA, SQL server development and some Oracle backend development work. I have been giving a task...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.