Login    
 
 
 
 
Text/HTML
  
You are here :: Blogs Saturday, May 19, 2012

Search
Note: This uses the internal blog search engine. The Google search engine is also available at the top of the page.
  
Disclaimer

Please review the site disclaimer before downloading or using content found on this site

  
Categories
  
DEVSHED Blog
As always, I welcome your comments!
Apr 20

Written by: Steve Gray
4/20/2010 10:30 AM  RssIcon

This simple stored proc will return all the fields in a SQL table, along with the data type. I use this when writing code against larger data structures where I don’t have the file names or data types memorized, it speeds writing procs.

In order to use this, you’ll also need f_4P_columnType.

Code Snippet
  1. -- 4/19/2010 created
  2.  
  3. IF EXISTS (SELECT name
  4.     FROM   sysobjects
  5.     WHERE  name = N'sp_fields'
  6.     AND    type = 'P')
  7.     DROP PROCEDURE sp_fields
  8. GO
  9.  
  10. CREATE PROCEDURE sp_fields
  11. --  sp_fields 'sop10100'
  12.  
  13. @vchrTableName varchar(50)
  14.  
  15. AS
  16.  
  17. select syscolumns.name , dbo.f_4P_columnType(xusertype,length,xprec,xscale) as fieldType
  18.     from sysobjects
  19.         left join syscolumns on syscolumns.id = sysobjects.id
  20.     where sysobjects.name = @vchrTableName
  21.     order by 1
  22.     
  23. go

Tags:
Categories:
Location: Blogs Parent Separator DEVSHED Blogs Child Separator SQL
As always, I welcome your comments!
  
 
 
Home | Products | Blogs | Contact Us | Links | God's Plan
Privacy Statement | Terms Of Use
 
Copyright 2011 by Devshed.us