i am trying to this query executed,But it print @TABLESQL11 value but not executed.Can any one help to execute.
declare @maxCount int
set @maxCount=3
DECLARE @TABLESQL11 VARCHAR(4000)
set @TABLESQL11='insert into temp11 '
set @TABLESQL11=@TABLESQL11+ 'select attendeeid,Activities,date,time'
DECLARE @j INT
SET @j =1
WHILE @j <=@maxCount
BEGIN
set @TABLESQL11 = @TABLESQL11+',q'+CONVERT(VARCHAR,@j)+',A'+CONVERT(VARCHAR,@j)
SET @j = @j+1
END
set @TABLESQL11=@TABLESQL11+' from temp1'
print @TABLESQL11
exec (@TABLESQL11)
Thanks in advance.
When you run all but the Exec you get the following (formatted in Instant SQL Formatter )
There’s nothing in the statement by itself to indicate that there’s a SQL Syntax issue. This leads one to conclude that the problem is one of the following.