--- Dynamic script workout DECLARE @ SQL NVARCHAR ( 500 ) , @ SQLOut NVARCHAR ( 500 ) , @ UserName NVARCHAR ( 50 ) , @ Columns NVARCHAR ( 100 ) , @ ParmDefinition NVARCHAR ( 100 ) , @ ParmDefinitionOut NVARCHAR ( 100 ) , @ Table NVARCHAR ( 128 ) , @ PersonID INT ; CREATE TABLE #Person ( [PersonId] INT , [FirstName] NVARCHAR ( 25 ) , [LastName] NVARCHAR ( 25 ) , [UserName] NVARCHAR ( 50 ) ) ; INSERT INTO #Person VALUES ( 1 , N ' Default ' , N ' Default ' , N ' Default.com.np ' ) , ( 2 , N ' Mik ' , N ' User ' , N ' admin@ad.com ' ) , ( 3 , N ' Kaww ' , N ' Poudel ' , N ' jhjv@gg.com.np ' ) ; SET @ Columns = ' FirstName, LastName,UserName ' ; SET @ Table = ' #Person ' ; SET @ PersonID = 2 ; -- adhoc - script SET @ SQL = ' SELECT ' + @ Columns + ' FROM ' +