Q: Trouble Getting Output Parameter from sp_executesql with input Parameters I am inserting a row into a remote MS SQL server and want to to retrieve the inserted row ID. I am using sp_executesql and passing in input parameters. The row is inserting but the OUTPUT parameter is null. Any idea why output parameter in NULL: 
DECLARE @QualificationId INT, @CourseId INT, @ModuleGrade INT,  @SQLString NVARCHAR(MAX), @ParmDefinition NVARCHAR(MAX); 


SET @ParmDefinition = N'@RemoteQualificationId INT, @RemoteCourseId INT,  @RemoteModuleGrade INT, @RemoteCourseAcademicDataId INT OUTPUT'; 

SET @SQLString = N'                         
INSERT INTO [ServerName].[DatabaseName].[dbo].[TableName]
(
    [RegYear],
    [SemesterId],
    [QualificationId],
    [CourseId],
    [AssessmentFinalGrade]
)
VALUES
(
    YEAR(GETDATE()),
    1,
    @RemoteQualificationId,
    @RemoteCourseId,
    @RemoteModuleGrade
)
SET @RemoteCourseAcademicDataId = SCOPE_IDENTITY()'


EXECUTE sys.sp_executesql
@SQLString,
@ParmDefinition,                                        
@RemoteQualificationId = @QualificationId,
@RemoteCourseId = @CourseId,
@RemoteModuleGrade = @ModuleGrade,
@RemoteCourseAcademicDataId = @CourseAcademicDataId OUTPUT;

