SQL Dynamic Table Name
Ofir Levi
May-2nd, 2019 13:16

In order to access a table in SQL while the Table name is dynamic you should use stored procedure. 

For example - first you need to create the stored procedure in the SQL data base. (You can do it using Microsoft management studio).

The below stored procedure will select the top 10 rows from the table.

CREATE PROCEDURE [dbo].[Dymanic_Query]

   @tablename as varchar(50)

AS

BEGIN

             DECLARE @query_a AS nvarchar(500)

             SET @query_a  = 'SELECT TOP 10  * FROM dbo.' +  @tablename

             EXECUTE sp_executesql @query_a

END



Then you need to call the stored procedure using query in UniLogic. 

[dbo].[Dymanic_Query] :TableName



Was this article helpful?
0 out of 0 found this helpful