Hello Everyone-I've the below query where I am referencing an employee table that has the following structure and has three employee recordsID FIRST_NAME EMAIL_ADDR123 DONALD DONALD@GMAIL.COM345 MAYANK MAYANKMIN@GMAIL.COM657 MAYANK_NEW MAYANKCGG@GMAIL.COMI'm passing name of this table (dbO.TD_EmployeeProfile_FinalV2) to get the counts from function FN_COUNT_ROWS (count is 3 as you can see above) so this while loop should run 3 times for all three employees. I'm having issues with statement "SELECT @EMP_ID" and "SELECT @EMAIL"DECLARE @email varchar(500),@intFlag INT,@INTFLAGMAX int,@TABLE_NAME VARCHAR(100),@EMP_ID INTSET @intFlag =1SET @TABLE_NAME='dbO.TD_EmployeeProfile_FinalV2'SELECT @INTFLAGMAX = ROW_COUNT FROM dbo.FN_COUNT_ROWS (@TABLE_NAME)AS X WHILE @intFlag <= @INTFLAGMAX BEGIN SELECT @EMP_ID = ID FROM (SELECT ID, ROW_NUMBER() OVER (ORDER BY ID ASC) ROW_NUM FROM (@TABLE_NAME)) WHERE ROW_NUM=@intFlag SELECT @EMAIL = EMAIL_ADDR FROM (SELECT EMAIL_ADDR, ID FROM (@TABLE_NAME)) WHERE ID=@EMP_ID EXEC msdb.dbo.Sp_send_dbmail @recipients =@email, @subject = 'email', @importance= 'high', @body = 'test123' SET @intFlag = @intFlag + 1 SET @intFlag = @intFlag + 1 END GO---ERRORS i'm gettingMsg 102, Level 15, State 1, Line 23Incorrect syntax near ')'.Msg 102, Level 15, State 1, Line 24Incorrect syntax near ')'
↧