exec sp_executesql N'INSERT [dbo].[Student]([StudentName], [StandardId]) VALUES (@0, NULL) SELECT [StudentID] FROM [dbo].[Student] WHERE @@ROWCOUNT > 0 AND [StudentID] = scope_identity(),@0='Bill'