View Full Version : Help with SQL


snoopy4801
12-22-2009, 02:20 PM
Ok, so new to SQL, probably a stupid question, but I have a performance database that i need to insert a new row for every employee for the new year and in the column "Fiscal Year" I want it to add 10. (so I would be inserting 850 records total)

The SQL I am using is:
INSERT INTO tbl Performance Tracking ([Fiscal Year]) VALUES ('10');

But it does not seem to be working, i just keep getting syntax errors.
Any Suggestions?:o

pbaldy
12-22-2009, 03:23 PM
That would only insert a single record. If you're getting a syntax error, the year field is probably numeric and you wouldn't want the 10 surrounded by quotes. Try the SELECT syntax instead of the VALUES syntax:

INSERT INTO ...
SELECT ...
FROM...

Where the FROM is a table containing the employees you want entered.

snoopy4801
12-23-2009, 07:51 AM
Ok, so here's where I'm at....Suggestions? Do I need to take out the Inner Join? I'm really only inserting the row on the Performance tracking table, but it's linked to the employees table....:o

SELECT
FROM [tbl Employee Table] INNER JOIN [tbl Performance Tracking] ON [tbl Employee Table].[Empl ID] = [tbl Performance Tracking].[Empl ID];
INSERT INTO tbl Performance Tracking ([Fiscal Year])VALUES (10);

pbaldy
12-23-2009, 07:55 AM
Try

INSERT INTO [tbl Performance Tracking] ([Empl ID], [Fiscal Year])
SELECT [Empl ID], 10
FROM [tbl Employee Table]

snoopy4801
12-23-2009, 08:21 AM
OMG!!! THANK YOU SO MUCH!!!!
That did it. Thank you, thank you!!!

pbaldy
12-23-2009, 08:27 AM
LOL! No problem, glad it worked for you.

The spaces in your names are not worth the bother in the long run, by the way. I'd get rid of them if it isn't too late.