Issues encountered with dynamic SQL
问题 ALTER PROCEDURE [dbo].[Create_Subjects] @Subj_ID nvarchar(9) AS DECLARE @First3Digits nvarchar(3); DECLARE @Result int; DECLARE @Sql nvarchar(max) -- Fetching the fiest 3 digits of the subject SET @First3Digits = SUBSTRING(@Subj_ID,1,3); -- Check if view is present or not IF EXISTS (SELECT 1 FROM sys.views WHERE Name = @First3Digits) BEGIN SET @Sql = 'select @Result = case when exists (select 1 from dbo.' + quotename(@First3Digits) + ' where SubjectName = ''' + @Subj_ID + ''') then 1 else 0