Insert into statement

I am trying to Insert values into a table using the following query and I get Query completed with errors and I don't know what is causing it.
Declare @gSource int;
Declare @bSource int;

Set @gSource = 143692;
Set @bSource = 138450;

/*SELECT ProjectID, BinderSection,BinderTab
FROM hcc_tblProjects2Sources
WHERE SourceID = @bSource
EXCEPT
SELECT ProjectID, BinderSection,BinderTab
FROM hcc_tblProjects2Sources
WHERE SourceID = @gSource;
*/

INSERT INTO hcc_tblProjects2Sources(ProjectID, BinderSection, BinderTab, SourceID)
VALUES(
	(SELECT ProjectID, BinderSection,BinderTab
	FROM hcc_tblProjects2Sources
	WHERE SourceID = @bSource
	EXCEPT
	SELECT ProjectID, BinderSection,BinderTab
	FROM hcc_tblProjects2Sources
	WHERE SourceID = @gSource)
	,@gSource
);

Open in new window


The part commented out returns 6 rows. I want to put those rows into a table and then a hard coded value of @gSource for all of them. Values returned by commented out section
Brandon GarnettAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
Wrong syntax. It is

INSERT INTO destinationName (fieldList)
SELECT fieldList 
FROM sourceName;

Open in new window


No VALUES part in this case.

This should work:

INSERT INTO hcc_tblProjects2Sources(ProjectID, BinderSection, BinderTab, SourceID)
SELECT ProjectID, BinderSection,BinderTab,@gSource
FROM hcc_tblProjects2Sources
WHERE SourceID = @bSource
EXCEPT
SELECT ProjectID, BinderSection,BinderTab,@gSource
FROM hcc_tblProjects2Sources
WHERE SourceID = @gSource;

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Nakul VachhrajaniTechnical Architect, Capgemini IndiaCommented:
Oh, you don't need VALUES clause if you are using a SELECT. This should work just fine...

Declare @gSource int;
Declare @bSource int;

Set @gSource = 143692;
Set @bSource = 138450;

/*SELECT ProjectID, BinderSection,BinderTab
FROM hcc_tblProjects2Sources
WHERE SourceID = @bSource
EXCEPT
SELECT ProjectID, BinderSection,BinderTab
FROM hcc_tblProjects2Sources
WHERE SourceID = @gSource;
*/

INSERT INTO hcc_tblProjects2Sources(ProjectID, BinderSection, BinderTab, SourceID)
SELECT ProjectID, BinderSection,BinderTab, @gSource
FROM hcc_tblProjects2Sources
WHERE SourceID = @bSource
EXCEPT
SELECT ProjectID, BinderSection,BinderTab, @gSource
FROM hcc_tblProjects2Sources
WHERE SourceID = @gSource;

Open in new window

Brandon GarnettAuthor Commented:
With those solutions does having @gSource change the Select Statement? I need it to Select the values for the first three and list the fourth and that statement will accomplish that?
Brandon GarnettAuthor Commented:
Thank you seems to be working great
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.