Uneven Technology

Friday, January 9, 2015

MSSQL - Read and Sort Column Names

USE AdventureWorks2012

DECLARE @TBLName nvarchar(128)
SET @TBLName = N'Person'


SELECT name, object_id FROM sys.tables WHERE name = @TBLName


SELECT name, column_id, object_id
FROM sys.columns
WHERE object_id IN (SELECT object_id FROM sys.tables WHERE name = @TBLName)
ORDER BY name
Posted by Sean T. at 12:27 PM
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest

No comments:

Post a Comment

Newer Post Older Post Home
Subscribe to: Post Comments (Atom)

Blog Archive

  • ►  2019 (2)
    • ►  Dec (1)
    • ►  Jul (1)
  • ►  2016 (2)
    • ►  May (1)
    • ►  Jan (1)
  • ▼  2015 (80)
    • ►  Dec (52)
    • ►  May (1)
    • ►  Apr (1)
    • ►  Mar (10)
    • ►  Feb (1)
    • ▼  Jan (15)
      • MSSQL - Permission Issue on OPENROWSET
      • MSSQL - View SQL Server Execution History
      • MSSQL - Sotred Procedure Template
      • MSSQL - Shrink All DBs
      • MSSQL - Shrink TempDB
      • MSSQL - List Running SQL Process
      • MSSQL - Read and Sort Column Names
      • MSSQL - Run SQL and Email Result as HTML
      • SSRS - Windows Command to Run Report
      • MSSQL - Addhoc Select from An Excel File
      • MSSQL - Using Excel File as A LinkedServer
      • SSRS - Adding Page Break
      • MSSQL - Find Blocking SQL
      • MSSQL - Rebuild DB Index
      • MSSQL - User Account Maintenance
  • ►  2013 (10)
    • ►  Nov (2)
    • ►  Jul (8)
  • ►  2012 (7)
    • ►  Aug (1)
    • ►  May (6)
Simple theme. Powered by Blogger.