Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple SQL INSERT assistance required

Status
Not open for further replies.

NeilBelgium

IS-IT--Management
Sep 18, 2001
87
BE
I'm trying to learn how to insert data into a table. I've worked out the connection, and the query.string to get the data.

However, I'm totally baffled by the SQL insert command.

The tutorials I have seen have far too much '"&"'&'"& which makes no sense to me.

Can someone give me some simple code to get the job done, and possibly explain why it is how it is
much appreciated, neil
 
There's two main forms of the insert statement. One for when you plan to change only a couple of columns, and one when you plan to change every column.

First type:
Code:
INSERT Table1 (column_2, column_1) VALUES ('Row #1',1)
Note that you can supply the columns out of order in which they're defined. Also note that a string value has single-quotes around it to delimit it. You'll have to make sure that if you supply a variable for this value, that any single-quotes in the variable have been doubled-up (i.e. 'Scott's' must become 'Scott''s')

Second type:
Code:
INSERT Table1 VALUES (1, 'Row #1', GETDATE())
Note that the columns must be specified in order. Also note that all columns have values. Again, string values are surrounded by single-quotes. I've also included the GetDate() function, which is part of MS SQL Server (it returns the current day & time as a datetime value).

It sounds cheezy, but the "SQL for Dummies" book is actually quite good, and covers nearly everything you'll need to know.

Chip H.
 
One problem with the insert statements. It should be "INSERT INTO TABLE1......" Mise Le Meas,

Mighty :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top