Input Parameters from a SQL Table

This blog defines the input parameters from an SQL Table.

use test
-- simple script for getting the input parameters from a sql table
create table tbl_inputparm
(
ID int primary key identity(1,1),
Name varchar(50),
Age Int ,
Address varchar(100)
)

Most of the SQL developer’s need to write stored procedures. When creating the stored procedures we need to pass some of the input parameters. Here is a simple script for Getting the Parameters from the SQL Table.

declare @tableName varchar(max)='tbl_inputparm'
select '@In_'+c.name+' '+cast(t.name as varchar(max) )+ cast((case when t.name=('varchar') then
'('+cast(c.max_length as varchar(max))+')' when t.name=('decimal') then '('+cast(c.precision as varchar(max))+','+cast(c.scale as varchar(max))+')'
else '' end) as varchar(max)) +'=null ,'[columnname] from sys.objects s join sys.columns c on s.object_id=c.object_id
join sys.types t on t.system_type_id=c.system_type_id where s.Type='U' and s.name=@tableName
output:
@In_ID int=null ,
@In_Age int=null ,
@In_Name varchar(50)=null ,
@In_Address varchar(100)=null ,