Re: Reformat Group membership table
- From: "Uri Dimant" <urid@xxxxxxxxxxx>
- Date: Thu, 3 Sep 2009 08:32:22 +0300
Hi
CREATE TABLE #t(c1 VARCHAR(20),c2 VARCHAR(100))
INSERT INTO #t VALUES ('Group1','User1,User2,User3')
INSERT INTO #t VALUES ('Group2','User4,User5')
INSERT INTO #t VALUES ('Group3','User6,User7,User8')
SELECT IDENTITY(INT) "n" INTO Numbers
FROM sysobjects s1
CROSS JOIN sysobjects s2
GO
SELECT c1,SUBSTRING(c2, n, CHARINDEX(',', c2 + ',', n) - n)
from numbers,#t where substring(','+c2,n,1)=','
AND n < LEN(c2) + 1
"reformat table" <reformat table@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:14AC1E72-4D6F-4371-9F38-0CD878034B04@xxxxxxxxxxxxxxxx
Environment is SQL 2000 SP4
I have a 3rd party application which exports ActiveDirectory group
membership to a SQL table. Each day the export process creates a table
with
the current date listed in the table name. The table is formatted as
shown
below with two columns:
Group1 User1%CR%User2%CR%User3
Group2 User4%CR%User5
Group3 User6%CR%User7%CR%User8
*I've inserted '%CR% where there is a carriage return.
The table has the group name in one column and the users names in the
second
column separated by carriage return.
I would like to run SQL queries that returns a result set which has all
the
users of a group... with each user on in a separate row. The only way I
believe I can do this effectively is to reformat the table to a format
something like the table shown below:
Group1 User1
Group1 User2
Group1 User3
Group2 User4
Group2 User5
Group3 User6
....
Then do some query like:
Select * From groupTable Where Group='Group2'
Results:
Group2 User4
Group3 User5
I'm looking for suggestions on how I can accomplish my SQL query...
whether
it's by reformatting the table and then running a query to determine the
group membership or maybe someone has a super secret query that will get
the
information I'm looking for. The other key to this is that I need a
solution
that is easy to implment since this group export occurs every day.
Your help is appreciated!
Brian
.
- Follow-Ups:
- Re: Reformat Group membership table
- From: BBF
- Re: Reformat Group membership table
- References:
- Reformat Group membership table
- From: reformat table
- Reformat Group membership table
- Prev by Date: Re: Format SQL time type
- Next by Date: Re: Selection by part of a field
- Previous by thread: Reformat Group membership table
- Next by thread: Re: Reformat Group membership table
- Index(es):
Relevant Pages
|