This is a far smaller version of a query that basically needs a variable of the table on which everything is run.
When I run the procedure I get the error message:
Msg 156, Level 15, State 1, Line 2 Incorrect syntax near the keyword 'table'.
alter procedure james_tester
@tablename nvarchar(200)
as
BEGIN
declare @sql nvarchar(max)
set @sql =
'
select * from '
+ @tablename
EXECUTE sp_executesql @sql
END
To fix this i tried using things like quotename and played around with the format but nothing seems to have worked yet.
execute james_tester 'dbo.Calendar table' (That is the table I am wanting to query)