Link to home
Start Free TrialLog in
Avatar of Brandon Garnett
Brandon Garnett

asked on

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. User generated image
ASKER CERTIFIED SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Brandon Garnett
Brandon Garnett

ASKER

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?
Thank you seems to be working great