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
Microsoft SQL Server* T-SQLSQL

Avatar of undefined
Last Comment
Brandon Garnett
ASKER CERTIFIED SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
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?
Avatar of Brandon Garnett

ASKER

Thank you seems to be working great
Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo