devxlogo

Declare Variables of the Right Datatype and Size while Creating Stored Procedure

Declare Variables of the Right Datatype and Size while Creating Stored Procedure

To help declare variables of the right datatype and size while creating Stored Procedures, this stored procedure accepts the name of the table and returns the variable list with all necessary information.

 Create proc sp_GetDataType@Name varchar(50)ASSELECT '@' + RTRIM(C.Name) + ' ' + RTRIM(T.Name) +	  case  	when (C.xtype = 167 or C.xtype = 175) then '(' +rtrim(cast(C.Length as char)) + ')'	  		else ''	  End + ','				 from sysobjects O, SYSCOLUMNS C, SYSTYPES TWHERE 	C.ID =  O.IdAND 	O.name = @NameAND	C.xtype = T.xtypeOrder by ColID--------------------------Result :--------------------------@EmployeeID int,@FirstName varchar(50),@LastName varchar(50),@DOJ smalldatetime,@SpecialUser bit,
See also  5 Tips for Working With an Onsite Interpreter
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist