Error while dynamically build query. Invalid Object Name


I use table name as input parameter of SQL Query to select data from external table and try to execute query.

I got the error as below.

Errors message :

Invalid object name 'CoABT.dbo.CoCounter'.

My Query: 

Select @EntityName.* From @EntityName

Input parameter (Expand Inline set to Yes) :



I try with other Query


SELECT {CoCountersABT}.* from {CoCountersABT}

It work.

I checked the generated query in Executed SQL. It's the same both.

Executed SQL:

 Select  [CoABT].[dbo].[CoCounters].[Id], [CoABT].[dbo].[CoCounters].[ColumnName], [CoABT].[dbo].[CoCounters].[Counter], [CoABT].[dbo].[CoCounters].[Filler1] From  [CoABT].[dbo].[CoCounters]

So can we use table name as input parameter to dynamic query??



Thanks @Goncalo Almeida . I tried but it doesn't work.


Invalid object name 'dbo.CoCounters'.
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.