How to get the columns in tha table?

The following code snippets will be used to get column name in particular table.


USE DBNAME

DECLARE @Schema varchar(60),
DECLARE @Table varchar(60),
DECLARE @columns varchar(1000)

SET @Table = 'Table_Name'
SET @Schema = 'Schema_Name'

SELECT @Columns = coalesce(@Columns + ', ', '') + column_name
FROM INFORMATION_SCHEMA.Columns
WHERE table_name = @Table
and table_Schema = @Schema
ORDER BY Ordinal_Position


SELECT @Columns



Regards,
Kavitha N


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: