Options

Error in SQL Prompt 9

OzzieOzzie Posts: 46 Bronze 5
This code will cause SQL Prompt to flag @totalRecords as 'Variable declared but never used.'
DECLARE
	@totalRecords INT;

IF OBJECT_ID('tempdb.dbo.#AssessmentDetails','U' ) IS NOT NULL
BEGIN
	DROP TABLE #AssessmentDetails
END

-- Must specify NULL/NOT NULL for columns creation
CREATE TABLE #AssessmentDetails
(
	id INT IDENTITY(1,1) NOT NULL, 
	planID INT NOT NULL, 
	planVersion INT NOT NULL, 
	planTry INT NOT NULL, 
	planInstance INT NOT NULL, 
	courseID INT NOT NULL,
	publishedcourseName VARCHAR(500) NOT NULL,
	CourseActive BIT NOT NULL,
	candidateId INT NOT NULL,
	candidateUserName VARCHAR(100) NOT NULL,
	candidateFirstname VARCHAR(50) NOT NULL,
	candidateLastName VARCHAR(50) NOT NULL,
	workGroupID VARCHAR(50) NOT NULL, 
	workGroupName VARCHAR(50) NOT NULL,
	CandidateScore INT NOT NULL, 
	PreOrPostFlag BIT NOT NULL,
	Assessmenttrydate DATETIME NOT NULL, 
	AssessmentTryNo INT NOT NULL, 
	RESULT VARCHAR(10) NOT NULL,
	Progress VARCHAR(10) NOT NULL,
	Score_details NVARCHAR(2000) NOT NULL
);

SELECT @totalRecords=COUNT(*) FROM #AssessmentDetails;
Tagged:

Answers

  • Options
    FabiolaBFabiolaB Posts: 54 Silver 3
    Hi @Ozzie,

    I have used your script and @totalRecords INT is reported as 'Variable declared but never used.'
    I think that is correct, as you are initializing @totalRecords=COUNT(*) but never actually use this variable.

    If you add, for example:
    SELECT * FROM [#AssessmentDetails] AS [ad] WHERE [ad].[planID] > @totalRecords
    

    at the end of your script, the issue will disappear.

    Regards,
    Fabiola

Sign In or Register to comment.