Skip to main content
Home
Blog

Main navigation

  • Home
User account menu
  • Log in

Breadcrumb

  1. Home
  2. Forums
  3. Knowledge Base
  4. How-To

MSSQL function get a list of fields of a particular table from system table

By ongetc , 26 February, 2017

Below is the actual code so you can just copy and paste to create the store procedure.


SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[ftvDescribe]
(
@tablename varchar(256)

)
RETURNS
TABLE
AS
RETURN
(
-- Fill the table variable with the rows for your result set
SELECT DISTINCT sCols.colid AS 'ID', sCols.name as FieldName, sTyps.name as FieldType, sCols.length as FieldLen
FROM [syscolumns] sCols
INNER JOIN [systypes] sTyps ON sCols.xtype = sTyps.xtype
INNER JOIN [sysobjects] sObjs ON sObjs.id = sCols.[id]
AND UPPER(sObjs.name) = UPPER(@tablename)
where sTyps.name <> 'sysname'

)

Forums
How-To

Reseller hosting (free)

Hosting24 (w/ ssh)

A2 Hosting

Monthly archive

  • September 2009 (14)
  • October 2009 (11)
  • January 2010 (2)
  • June 2010 (3)
  • October 2011 (1)
  • March 2012 (1)
  • July 2012 (1)
  • February 2017 (564)
  • March 2017 (5)
  • April 2017 (2)

Pagination

  • 1
  • Next page

Popular content

Last viewed:

  • F3Site
  • How to do normal URL with Zend Framework?
  • CuteNews
  • Piwigo
  • Geeklog
  • PDF pages counting using VB script.
  • Diem
  • DotNetNuke
  • widgEditor
  • hosting24.com

User login

  • Reset your password