Drop Table

Support Forum for database administrators and web based access to important newsgroups related to databases
Register on Database Support Forum Edit your profileCalendarFind other Database Support forum membersFrequently Asked QuestionsSearch this forum -> 
For Database admins: Free Database-related Magazines Now Free shipping to Texas


Post New Thread










Thread
Author

splitting a comma seperated column into multiple rows
Hi i want to create a table as follows :

if exists (select * from dbo.sysobjects where id =
object_id(N'[Indexes]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [Indexes]
GO

Create table Indexes(indexname Varchar(100), index_Description
Varchar(100), index_keys Varchar(100))
GO

INSERT INTO Indexes EXEC sp_helpindex  'SDM_Fact_Order_Deta
il'
GO

This will give me a table (northwind)

 IX_Auto_SDM_Fact_FK_
Shipped_Date nonclustered located on
SAMIS_SDM_Index FK_Shipped_Date

 IX_Auto_SDM_Fact_Ord
 er_Detail_FK_Insert_
Date	clustered located on
 SAMIS_SDM_Data1	FK_I
nsert_Date, FK_Insert_Time

As you see sp_helpindex  will give me a comma seperated field. I want
to split the third column FK_Insert_Date, FK_Insert_Time into a extra
row
Like this :

 IX_Auto_SDM_Fact_FK_
Shipped_Date                 FK_Shipped_Date
 IX_Auto_SDM_Fact_Ord
 er_Detail_FK_Insert_
Date FK_Insert_Date
 IX_Auto_SDM_Fact_Ord
 er_Detail_FK_Insert_
Date FK_Insert_Time

Can anyone help me with this?

Thanx

Hennie


Report this thread to moderator Post Follow-up to this message
Old Post
Hennie7863
01-18-06 02:23 PM


Re: splitting a comma seperated column into multiple rows
Hi, Hennie

If you need the columns that are part of an index for a specified
table, you can use something like this:

SELECT i.name as IndexName, c.name as ColumnName
FROM sysindexes i
INNER JOIN sysindexkeys k ON i.id=k.id AND i.indid=k.indid
INNER JOIN syscolumns c ON c.id=k.id and c.colid=k.colid
WHERE i.id=OBJECT_ID('Order Details')

If you really want to split some other comma-delimited value (that
cannot be obtained in any other way), see this article by Erland
Sommarskog, SQL Server MVP:
http://www.sommarskog.se/arrays-in-sql.html

Razvan


Report this thread to moderator Post Follow-up to this message
Old Post
Razvan Socol
01-18-06 02:23 PM


Sponsored Links





Last Thread Next Thread
Post New Thread

Microsoft SQL Server forum archive

Show a Printable Version Email This Page to Someone! Receive updates to this thread
Microsoft SQL Server
Access database support
PostgreSQL Replication
SQL Server ODBC
FoxPro Support
PostgreSQL pgAdmin
SQL Server Clustering
MySQL ODBC
Web Applications with dBASE
SQL Server CE
MySQL++
Sybase Database Support
MS SQL Full Text Search
PostgreSQL Administration
SQL Anywhere support
DB2 UDB Database
Paradox Database Support
Filemaker Database
Berkley DB
SQL 2000/2000i database
ASE Database
Forum Jump:
All times are GMT. The time now is 04:11 AM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006