Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Enterprise
Expertise: Beginner
Oct 26, 2001

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)
AS
SELECT '@' + 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 T
WHERE 	C.ID =  O.Id
AND 	O.name = @Name
AND	C.xtype = T.xtype
Order by ColID

--------------------------
Result :
--------------------------
@EmployeeID int,
@FirstName varchar(50),
@LastName varchar(50),
@DOJ smalldatetime,
@SpecialUser bit,
Anitha Balaji
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date