I am trying to insert data into one table, select from another table based on if condition but is not working for either if condition. Parameteres are provided corectly, I've checked that. What am I doing wrong?
CREATE PROCEDURE [dbo].[AddTestDetail] @IdUserTest AS int, @Complexitate AS nvarchar AS BEGIN IF (@Complexitate = 'GENERAL') BEGIN INSERT INTO tblTestDetail (IdIntrebare, IdUserTest) SELECT ti.IdIntrebare AS IdIntrebare, @IdUserTest FROM (SELECT TOP 10 * FROM tblIntrebare ORDER BY NEWID()) ti JOIN tblRaspuns tr ON ti.IdIntrebare = tr.IdIntrebare JOIN tblProcedura tp ON ti.IdProcedura = tp.IdProcedura WHERE tp.Sectiune = 'GENERAL'; END IF (@Complexitate = 'SPECIFIC') BEGIN INSERT INTO tblTestDetail (IdIntrebare, IdUserTest) SELECT ti.IdIntrebare AS IdIntrebare, @IdUserTest FROM (SELECT TOP 10 * FROM tblIntrebare ORDER BY NEWID()) ti JOIN tblRaspuns tr ON ti.IdIntrebare = tr.IdIntrebare JOIN tblProcedura tp ON ti.IdProcedura = tp.IdProcedura WHERE tp.Sectiune = 'GENERAL'; INSERT INTO tblTestDetail (IdIntrebare, IdUserTest) SELECT ti.IdIntrebare AS IdIntrebare, @IdUserTest FROM (SELECT TOP 10 * FROM tblIntrebare ORDER BY NEWID()) ti JOIN tblRaspuns tr ON ti.IdIntrebare = tr.IdIntrebare JOIN tblProcedura tp ON ti.IdProcedura = tp.IdProcedura WHERE tp.Sectiune = 'SPECIFIC'; END END