Obtain all columns separated by commas (,) in a table or view.

Source: Internet
Author: User
Obtain the development environment of all columns separated by commas (,) for a table or view: in SQL Server 2005, we often need to obtain all columns of a table or view during work, return a comma-separated column name. The following are two methods: 1. Directly drag 【 Column] Table query analyzer. 2. Write the program process. Because it is a stored procedure starting with SP _, it is recommended to write it in the master database so that it can be called in any database. The script is as follows: if object_id ('SP _ gettablecolumns ', 'P ') is not nulldrop proc sp_gettablecolumnsgo/********************** proc: sp_gettablecolumnsuse: Get a table or view with comma ', 'create by: Mark yaocreate Date: 2008/7/3 input: @ tblname table or view name output: E. g: sp_gettablecolumns 'teaminfo' *********************/create proc sp_gettablecolumns @ tblname nvarchar (200) asselect substring (select ',' + name from syscolumns where id = object_id (@ tblname) order by colorder for XML Path (''), 2,1000) Go

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.