473,503 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 13909
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
6211
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
21321
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
2865
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
6646
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
3077
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
3307
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
1339
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
8183
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
2208
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
7204
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7091
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...
0
7282
Oralloy
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,...
0
7464
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5586
agi2029
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,...
1
5018
isladogs
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...
0
4680
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...
0
3162
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
391
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.