473,404 Members | 2,187 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,404 software developers and data experts.

Need help with Query

Hi, I need help with a query and I'm having trouble getting it formed correctly. I have 3 tables: users, authorization_users, and reports.

The user table contains a bunch of users with fields like userID, first_name, last_name, and such.

The authorization_users table contains a permID which is the key from the reports table, userID, and a Value (bit)

The Reports table contains a permID, reportName, and a few other fields.

I'm trying to construct a Stored Proc that will accept a username as a parameter to query the users, authorization_users, and reports table and return all reports that a single user has displaying the report name and it's associated value (true/false).

Here is what I have

CREATE PROC dbo.sp_GetReportPermissions
@username varchar
AS
SELECT rpt.reportName, au.[Value], us.UserName
FROM dbo.authorization_users, dbo.reports, dbo.users
WHERE us.UserName = @username AND au.UserID = us.UserID AND rpt.PermID = au.PermID

Can someone help me to form this correctly to obtains the results mentioned above?

Trying to get results in the form of:

UserID UserName Report Value

1 JoeUser MarketingRpt 1
1 JoeUser FinanceRpt 0
1 JoeUser SalesRpt 1
Aug 5 '07 #1
1 1177
ck9663
2,878 Expert 2GB
Hi, I need help with a query and I'm having trouble getting it formed correctly. I have 3 tables: users, authorization_users, and reports.

The user table contains a bunch of users with fields like userID, first_name, last_name, and such.

The authorization_users table contains a permID which is the key from the reports table, userID, and a Value (bit)

The Reports table contains a permID, reportName, and a few other fields.

I'm trying to construct a Stored Proc that will accept a username as a parameter to query the users, authorization_users, and reports table and return all reports that a single user has displaying the report name and it's associated value (true/false).

Here is what I have

CREATE PROC dbo.sp_GetReportPermissions
@username varchar
AS
SELECT rpt.reportName, au.[Value], us.UserName
FROM dbo.authorization_users, dbo.reports, dbo.users
WHERE us.UserName = @username AND au.UserID = us.UserID AND rpt.PermID = au.PermID

Can someone help me to form this correctly to obtains the results mentioned above?

Trying to get results in the form of:

UserID UserName Report Value

1 JoeUser MarketingRpt 1
1 JoeUser FinanceRpt 0
1 JoeUser SalesRpt 1
how about this:

SELECT rpt.reportName, au.[Value], us.UserName
FROM dbo.authorization_users au, dbo.reports rpt, dbo.users us
WHERE us.UserName = @username AND au.UserID =* us.UserID AND rpt.PermID =* au.PermID
Aug 6 '07 #2

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

Similar topics

2
by: lawrence | last post by:
I've been bad about documentation so far but I'm going to try to be better. I've mostly worked alone so I'm the only one, so far, who's suffered from my bad habits. But I'd like other programmers...
9
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use...
6
by: paii | last post by:
I have a table that stores job milestone dates. The 2 milestones I am interested in are "Ship Date" TypeID 1 and "Revised Ship Date" TypeID 18. All jobs have TypeID 1 only some jobs have TypeID 18....
3
by: pw | last post by:
Hi, I am having a mental block trying to figure out how to code this. Two tables: "tblQuestions" (fields = quesnum, questype, question) "tblAnswers" (fields = clientnum, quesnum, questype,...
7
by: K. Crothers | last post by:
I administer a mechanical engineering database. I need to build a query which uses the results from a subquery as its input or criterion. I am attempting to find all of the component parts of...
3
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems...
0
by: ward | last post by:
Greetings. Ok, I admit it, I bit off a bit more than I can chew. I need to complete this "Generate Report" page for my employer and I'm a little over my head. I could use some additional...
10
by: L. R. Du Broff | last post by:
I own a small business. Need to track a few hundred pieces of rental equipment that can be in any of a few dozen locations. I'm an old-time C language programmer (UNIX environment). If the only...
7
by: Rnykster | last post by:
I know a little about Access and have made several single table databases. Been struggling for about a month to do a multiple table database with no success. Help! There are two tables. First...
3
by: pbd22 | last post by:
Hi. I need some help with structuring my query strings. I have a form with a search bar and some links. Each link is a search type (such as "community"). The HREF for the link's anchor looks...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.