Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old March 27th, 2005, 11:09 AM
humeaub humeaub is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 5 humeaub User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 25 sec
Reputation Power: 0
Question basic : how to insert a date in a table ?

Hi all,

I am new here. I am a student and I am working on
SQL Server 2000. I am kind of lost ... I have never used it in the past. I am trying to create a database and one of tables has a date. I couldn't find how to declare a date, I chose DATETIME (I don't know if it is correct).

I have created the following table :

CREATE TABLE SALARIE
( NUMSAL INTEGER PRIMARY KEY,
NOMSAL VARCHAR(15),
PRENOMSAL VARCHAR(15),
ADRESSSAL VARCHAR(30),
VILLESAL VARCHAR(15),
CODEPSAL INTEGER,
DATEEMB DATETIME);

But, I can't find how to insert information in it. Can someone help me please ?

For example, let us say I would like to insert :
NUMSAL : 25
NOMSAL : HUMEAU
PRENOMSAL : Bertrand
ADRESS : 4 rue de Paris
VILLESAL : Paris
CODEPSAL : 75012
DATEEMB : 25/12/2005

I tried this but doesn't work :

INSERT INTO SALARIE VALUES (1, "GERBIER", "Luc", "19 bd Jean Jaurès", "LA TOUR DE SALVAGNY", 69890, "02-01-1990");

Other try 1 :[/b]

screenshot



String and binary datas will be cut/truncated.

Other try 2 :

Screen shot
I typed INSERT.... (we can't see the first letter of INSERT)


Syntax error for the conversion of a date from a string.

[b]Other try 3 :
I was told to use the syntax NUMERIC(numberofinteger)
instaed of INTEGER when creating the table. So I created again the table (deleted it first).

CREATE TABLE SALARIE
( NUMSAL NUMERIC(2) PRIMARY KEY,
NOMSAL VARCHAR(15),
PRENOMSAL VARCHAR(15),
ADRESSSAL VARCHAR(30),
VILLESAL VARCHAR(15),
CODEPSAL NUMERIC(5),
DATEEMB DATETIME);

I was that to insert a date we must put it between "", and that it is "year-day-month".

I made another try ...


The name 'GERBIER' is not allowed in this context. Only contants, expressions, and variables are allowed. Column names are not allowed.

No column is called GERBIER. I don't understand.


Any idea ?

Thanks for your help.

I am under SQL Server 2000 SP2.

Reply With Quote
  #2  
Old March 27th, 2005, 11:51 AM
Calldean's Avatar
Calldean Calldean is offline
Semi-Retired Geek
ASP Free Novice (500 - 999 posts)
 
Join Date: Mar 2005
Location: Liverpool
Posts: 681 Calldean User rank is Corporal (100 - 500 Reputation Level)Calldean User rank is Corporal (100 - 500 Reputation Level)Calldean User rank is Corporal (100 - 500 Reputation Level)Calldean User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 20 h 46 m
Reputation Power: 6
First off; don't use " use '.

That should stop it thinking you are refering to columns.

Reply With Quote
  #3  
Old March 27th, 2005, 01:27 PM
humeaub humeaub is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 5 humeaub User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 25 sec
Reputation Power: 0
I have installed SQL Server 2000 in English. From an original CD.

So, I could try what you said and I did again what was above. Here are the results with the error messages in English (no wrong or approximative translation).

IN English :
-- Creating the table
CREATE TABLE SALARIE
( NUMSAL NUMERIC(2) PRIMARY KEY,
NOMSAL VARCHAR(15),
PRENOMSAL VARCHAR(15),
ADRESSSAL VARCHAR(30),
VILLESAL VARCHAR(15),
CODEPSAL NUMERIC(5),
DATEEMB DATETIME);

Try 1:

INSERT INTO SALARIE VALUES (1, "GERBIER", "Luc", "19 bd Jean Jaurès", "LA TOUR DE SALVAGNY", 69890, "19900201");

Error message :

Server: Msg 128, Level 15, State 1, Line 1
The name 'GERBIER' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.

Try 2:

INSERT INTO SALARIE VALUES ("1", "GERBIER", "Luc", "19 bd Jean Jaurès", "LA TOUR DE SALVAGNY", "69890", "19900201");

Error message :
Server: Msg 128, Level 15, State 1, Line 1
The name '1' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.

Try 3:
INSERT INTO SALARIE VALUES ('1', 'GERBIER', 'Luc', '19 bd Jean Jaurès', 'LA TOUR DE SALVAGNY', '69890', '19900201');
Error message :
Server: Msg 8152, Level 16, State 9, Line 1
String or binary data would be truncated.
The statement has been terminated.

Try 4 (removing the ; and using ' instead of ") :

INSERT INTO SALARIE VALUES (1, 'GERBIER', 'Luc', '19 bd Jean Jaurès', 'LA TOUR DE SALVAGNY', 69890, '19900201')

Error message :
Server: Msg 8152, Level 16, State 9, Line 1
String or binary data would be truncated.
The statement has been terminated.

Try 5 (removing the ; but keeping the ") :

INSERT INTO SALARIE VALUES (1, "GERBIER", "Luc", "19 bd Jean Jaurès", "LA TOUR DE SALVAGNY", 69890, "19900201")

Error message :
Server: Msg 128, Level 15, State 1, Line 1
The name 'GERBIER' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.

Try 6 :
INSERT INTO SALARIE VALUES (1, GERBIER, Luc, 19 bd Jean Jaurès, LA TOUR DE SALVAGNY, 69890, 19900201)

Error message :
Server: Msg 128, Level 15, State 1, Line 1
The name 'GERBIER' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.

Reply With Quote
  #4  
Old March 27th, 2005, 04:26 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,776 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 27 m 42 sec
Reputation Power: 470
Try this
Code:
INSERT INTO Salarie VALUES(1, 'GERBIER', 'Luc', '19 bd Jaures', 'LA TOUR DE SALVAGNY' 69890, '19900201')

Reply With Quote
  #5  
Old March 28th, 2005, 03:34 AM
humeaub humeaub is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 5 humeaub User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 25 sec
Reputation Power: 0
Hi, actually it works this way :

INSERT INTO SALARIE VALUES ('6','TEST','Beber','1 et ca marche','VILLEURBANNE','92340','22-03-1959')

Or ('03-22-1959') don't remember exactly.

Thank you for your reply.

Reply With Quote
  #6  
Old March 28th, 2005, 01:41 PM
mehere's Avatar
mehere mehere is offline
Senior Sarcasm Wizardess
Click here for more information.
 
Join Date: Feb 2005
Location: Dreamland
Posts: 12,867 mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 10976 Folding Title: Novice Folder
Time spent in forums: 4 Months 4 Weeks 15 h 20 m 54 sec
Reputation Power: 1762
Quote:
Originally Posted by humeaub
INSERT INTO SALARIE VALUES (1, 'GERBIER', 'Luc', '19 bd Jean Jaurès', 'LA TOUR DE SALVAGNY', 69890, '19900201')

Error message :
Server: Msg 8152, Level 16, State 9, Line 1
String or binary data would be truncated.
The statement has been terminated.

VILLESAL VARCHAR(15),


With the above insert, the section marked in red is more than the 15 character limit you made for that field.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > basic : how to insert a date in a table ?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT