October 7, 2008 at 2:01 am
Below is a query which works fine. it dispays the table name,index name and associated column name.
SELECT obj.name tableName,
ind.name AS IndexName,
col.name AS ComponentName
FROM dbo.syscolumns Col
RIGHT OUTER JOIN dbo.sysindexkeys as indkey
INNER JOIN dbo.sysobjects obj ON indkey.id = obj.id
INNER JOIN dbo.sysindexes ind ON indkey.indid = ind.indid AND obj.id = ind.id
ON
col.id = obj.id AND col.colid = indkey.colid
WHERE obj.name='my_table' and (ind.indid BETWEEN 1 AND 254) AND (ind.Status & 64)=0
However it is displayed if there is an index name in 2 columns, there is two rows which is outputted as below:
TableName Indexname ComponentName
table1 IX_1 col1
table1 IX_1 col2
What i want is to output the records as follows, where there is a single record for both column ( I dont want to use cursor here):
TableName Indexname ComponentName
table1 IX_1 col1,col2
Please post if you have any ideas.
Amit
October 7, 2008 at 7:29 am
This type of concatenation is usually a bad idea especially if your intent is to store the result somewhere in the database as permanent data (not that you are, but had to say it "out loud"). 🙂
Please take a look at the following article. It's got a pretty good "how to" in it as well as some performance pitfalls to avoid...
http://www.sqlservercentral.com/articles/Test+Data/61572/
--Jeff Moden
Change is inevitable... Change for the better is not.
October 7, 2008 at 9:01 am
Also refer
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254
Failing to plan is Planning to fail
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply