Hi Shambhu Rai ,
Thankyou for using Microsoft Q&A platform and thanks for posting your question here.
As per my understanding, you want to generate a dynamic SQL query that selects all columns from a table specified by its name, you can create procedure in SQL like below which takes the tablename as input and run the select statement for that table:
CREATE PROCEDURE GetTableData
@tbl_name NVARCHAR(100)
AS
BEGIN
DECLARE @query NVARCHAR(MAX);
SET @query = N'SELECT * FROM ' + QUOTENAME(@tbl_name);
EXEC sp_executesql @query;
END;
Run the above stored procedure by using the below command:
exec GetTableData 'student_external1dd123'
Hope it helps. Kindly accept the answer by clicking on Accept answer
button. Thankyou