473,378 Members | 1,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Help with parsing assigned groups and roles

This is my problem

Table 1 is a list of reports that have the following columns

Report ID, Report Name, Groups Allowed, Roles Allowed
1 Report 1 Clerk, Mgr User, PowerUser

Table 2 is a list of users

UserID, User Name, Group, Role
u1 John Doe Clerk User
u2 Jane Doe Mgr PowerUser

How do i loop thru the reports table 1 and select the reports based on Group and Role in the user table 2?

I have already got a function to parse the columns
as follows


CREATE FUNCTION ParseString2Table
(
@SourceString varchar(100)
)

RETURNS @retTable TABLE
(
TextValue varchar(10)
)

AS

BEGIN
declare @string varchar(500)
set @string = @SourceString
declare @pos int
declare @piece varchar(10)

/*-- Need to tack a delimiter onto the end of the input string if one doesn't exist*/
if right(rtrim(@string),1) <> ','
set @string = @string + ','

set @pos = patindex('%,%' , @string)
while @pos <> 0
begin
set @piece = left(@string, @pos - 1)

/*-- You have a piece of data, so insert it, print it, do whatever you want to with it.*/
INSERT INTO @retTable VALUES( cast(@piece as varchar(10)))

set @string = stuff(@string, 1, @pos, '')
set @pos = patindex('%,%' , @string)
end

RETURN

END

I need some way of looping thru the reports table without using a cursor and
checking the user permissions

Help Please...
Apr 4 '07 #1
10 1528
iburyak
1,017 Expert 512MB
Not sure if I understand correctly values in following columns

Groups Allowed, Roles Allowed



Nicenjgirl
Apr 4 '07 #2
Not sure if I understand correctly values in following columns

Groups Allowed, Roles Allowed



Nicenjgirl

Well I guess I should not have used User & Mgr as examples.
Let's say 2 different departments - Manufacturing & Finishing

so the Groups Allowed column is varchar (1000) and would be
"MAN, FIN, DELIVERY"
and the Roles Allowed columnd is also varchar(1000) and would be something like
"User, PowerUser"
Apr 4 '07 #3
iburyak
1,017 Expert 512MB
I think I got it without your last reply.

See what I did.

1. Create tables and populate with data:

[PHP]create table table1(ReportID varchar(10), ReportName varchar(10), GroupsAllowed varchar(100), RolesAllowed varchar(100))
insert into table1 values ('1 Report', '1 Clerk', 'Mgr User', 'PowerUser')
insert into table1 values ('2 Report', '1 Clerk', 'User', 'PowerUser User')


Create table table2(UserID varchar(10), UserName varchar(20), [Group] varchar(100), Role varchar(20))
insert into table2 values ('u1', 'John Doe', 'Clerk', 'User')
insert into table2 values ('u2', 'Jane Doe', 'Mgr', 'PowerUser')[/PHP]


2. Create Function

[PHP]CREATE FUNCTION fnSplit(@String nvarchar(1000), @Delimiter char(1), @SearchFor varchar(100))
RETURNS varchar(100)
AS

BEGIN
DECLARE @INDEX INT
DECLARE @SLICE nvarchar(4000)
DECLARE @OriginalString varchar(4000)

SELECT @OriginalString = @String
SELECT @INDEX = 1
WHILE @INDEX !=0


BEGIN
-- GET THE INDEX OF THE FIRST OCCURENCE OF THE SPLIT CHARACTER
SELECT @INDEX = CHARINDEX(@Delimiter,@STRING)
-- NOW PUSH EVERYTHING TO THE LEFT OF IT INTO THE SLICE VARIABLE
IF @INDEX !=0
SELECT @SLICE = LEFT(@STRING,@INDEX - 1)
ELSE
SELECT @SLICE = @STRING
-- PUT THE ITEM INTO THE RESULTS SET
IF @SLICE = @SearchFor
BEGIN
RETURN @SLICE
END

-- CHOP THE ITEM REMOVED OFF THE MAIN STRING
SELECT @STRING = RIGHT(@STRING,LEN(@STRING) - @INDEX)
-- BREAK OUT IF WE ARE DONE
IF LEN(@STRING) = 0 BREAK
END
RETURN NULL
END [/PHP]

3. Run query:

[PHP]select *
from table1 a
join table2 b on dbo.fnSplit(a.RolesAllowed, ' ', b.role) = b.role[/PHP]


Good Luck.

Hope it works.
I tested and it did work for me.
Apr 4 '07 #4
iburyak
1,017 Expert 512MB
I used space for delimiter like in your first example but you can change it to comma if you wish.

Good Luck again.


VeryNiceNJGirl.... :)
Apr 4 '07 #5
I used space for delimiter like in your first example but you can change it to comma if you wish.

Good Luck again.


VeryNiceNJGirl.... :)
Thanks a ton!!

NiceNJGirl.. You are the best!
Apr 5 '07 #6
iburyak
1,017 Expert 512MB
[font=Verdana][size=2]To tell you the truth I never wrote queries like that and was amazed that it worked... :) [/size][/font]
[font=Verdana][size=2]You don't need to loop through your table any more.[/size][/font]
[font=Verdana][size=2][/size][/font]
[font=Verdana][size=2][/size][/font]
[font=Verdana][size=2]It was a good one even thou I disapprove multiple values in one column. Poor design period.[/size][/font]
[font=Verdana][size=2] [/size][/font]
[font=Verdana][size=2]Good Luck.[/size][/font]
Apr 5 '07 #7
iburyak
1,017 Expert 512MB
What was it?

I will try again to post my message:

To tell you the truth I never wrote queries like that and was amazed that it worked... :)
You don't need to loop through your table any more.


It was a good one even thou I disapprove multiple values in one column. Poor design period.

Good Luck.
Apr 5 '07 #8
What was it?

I will try again to post my message:

To tell you the truth I never wrote queries like that and was amazed that it worked... :)
You don't need to loop through your table any more.


It was a good one even thou I disapprove multiple values in one column. Poor design period.

Good Luck.
Dear VeryNiceNJGirl,

I know it is poor design. Guess I could add a couple of satellite tables.
Maybe you have encountered this situation before and have a data model handy?
Apr 5 '07 #9
iburyak
1,017 Expert 512MB
You just need extra tables for Reports

[PHP]Create table ReportRoles(
ReportID datatypehere,
Role datatypehere)

Create table ReportGroups(
ReportID datatypehere,
Group datatypehere)[/PHP]

The same should be done for users.
This way you would be able to join reports, users and its rights and groups.

Hope it is understandable.

Irina.
Apr 5 '07 #10
You just need extra tables for Reports

[PHP]Create table ReportRoles(
ReportID datatypehere,
Role datatypehere)

Create table ReportGroups(
ReportID datatypehere,
Group datatypehere)[/PHP]

The same should be done for users.
This way you would be able to join reports, users and its rights and groups.

Hope it is understandable.

Irina.
Yes it is and thanks again. You have been very helpful.

Kenny
Apr 5 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Bob C. | last post by:
I am converting a relatively large multi-user Access 97 database to SQL Server 2000. I use about a dozen groups to manage security, providing graduated levels of access to each group. I read that...
2
by: phreeskier | last post by:
i want to implement authorization with windows authentication and don't have the slightest clue of how to do this implementation. the basic windows authentication for this .NET application is...
28
by: stu_gots | last post by:
I have been losing sleep over this puzzle, and I'm convinced my train of thought is heading in the wrong direction. It is difficult to explain my circumstances, so I will present an identical...
2
by: Roderick A. Anderson | last post by:
While playing at a new/different configuration in my brand spanking new Pg 7.4 instance :-) I noticed in the documentation that GROUPs are not in the SQL Standard. So I go a looking and notice...
1
by: poi | last post by:
I have a Win2K and Win2K web servers with Local Groups that contain domain users and domain groups from a foreign trusted domain. In the web config for the application, the web.config has this: ...
6
by: Mr Newbie | last post by:
Hi, Im in a situation where I need to restrict users, but I dont have access or wont be allowed access to manage groups in the domain. How can I restrict access is this case ? -- Best...
6
by: Chris | last post by:
I'm looking to protect some pages using the Membership provider (ADS) built into .NET 2.0. In order to protect these pages, whose details are stored inside a SQL Server table with columns...
4
by: Burak Gunay | last post by:
Hello, I derived a custom provider from the provider class. I set cookieless="UseUri" in the web.config, because we don't want data stored on client machines. Now, as I understand it,...
1
by: Andy | last post by:
Hi, I currently have my application setup and built using Windows Authentication (WindowsPrincipal). For security checks, I simply do an IsInRole call on the Principal. The role permissions...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.