top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to Check Columns name and their types using Store Procedure?

+1 vote
447 views
How to Check Columns name and their types using Store Procedure?
posted Mar 29, 2016 by Sathyasree

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes
CREATE PROCEDURE CheckTable
 @TableName varchar(50)
 AS


 BEGIN
 SELECT name AS [Column Name], --length,xtype, 
 CASE xtype
   WHEN 56 THEN 'int'
   WHEN 167 THEN 'varchar(' + convert(varchar(10),length) + ')'
   WHEN 61 THEN 'dateTime'
   WHEN 104 THEN 'bit'
   WHEN 52 THEN 'smallint'
   WHEN 175 THEN 'char(' + convert(varchar(10),length) + ')'
   END AS [Column Type] 
   FROM syscolumns
   WHERE id IN ( SELECT id FROM sysobjects where name = @TableName )
   RETURN
end

GO
answer Mar 29, 2016 by Shivaranjini
Similar Questions
+4 votes

how to check if table exist and if it doesnt exist create table in sql server 2008

+1 vote

I have created two list boxes.
listbox1 has single selection and listbox 2 has multi-selection and 3 text-boxes. I want to insert the selected items from both list-boxes as well as data entered from text-boxes at same time. I mean same statement insert using c#.

...