I am trying to create a select statement that can return a table of 1 column.
Basically, I am looping through all the records of
NewHire, and then using its id, to select stuff from another table. I then do a count to get the number of rows, and then divide to get a percentage value, and then I want to insert it to this temp table
t. Then select
t. But this isn't working. I am getting syntax errors.
Does anyone know how to fix this?
declare @t table (Percentage int) DECLARE @acc INT SET @acc = 1 DECLARE @max INT select @max = max(HireID) from NewHire WHILE (@acc <= @max) BEGIN IF (@acc in (select HireID from NewHire)) BEGIN insert into @t (select COUNT(*) from Hire_Response WHERE HireID = @acc) / (select COUNT(*) from Hire_Response WHERE HireID = @acc AND (HireResponse = 0 OR HireResponse = 1)) END set @acc = @acc + 1 END select * from @t