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

Simple Case Statement Help

Hello.

I am trying to execute a statement that works fine in ms sql but will
not work in mysql. There are three tables. user (user_sid,
user_name, user_email), file (file_sid, file_name, file_desc),
file_access (file_sid, user_sid).

Here is what I want:
Given a particular file_sid return all users with an extra column
(1,0) inticated whether or not there was a match in the file_access
table for given file_sid. here is what I attempted that DOES work in
mssql.

select case when not (select file_access.user_sid from file_access
where file_access.file_sid=1 and file_access.user_sid=user.user_sid)
is null then 1 else 0 end as has_access, user.* from user
PLEASE HELP...
Jul 20 '05 #1
2 1624
"Trent" <tr*********@earthlink.net> wrote in message
Given a particular file_sid return all users with an extra column
(1,0) inticated whether or not there was a match in the file_access
table for given file_sid. here is what I attempted that DOES work in
mssql.


Would group by help? It's not exactly the same thing you're looking for,
but maybe can be tweaked.

select file.name, count(*)
from file
left outer join fileuser on file.id = fileuser.file_id
left outer join user on fileuser.user_id = user.id
group by file.name

If you really need 0, 1 then maybe there's another function you can use in
place of count(*). A simple if(...) or case comes to mind, but it has the
disadvantage of counting all the rows whereas you need to see if there is at
least one row (ie. stop counting at 1 row). So somewhere, somehow, a limit
1 might be helpful.
Jul 20 '05 #2
While that statement did prove to give back a count of users with
access to each file, I am wanting something different. With one query
I want ALL users displayed in a list on a webpage. The list will also
contain a checkbox. the checkbox will look for the extra column (1 or
0) and if one will place SELECTED in the checkbox when writing to the
screen.

FOR EXAMPLE:

File Access for test_doc.PDF

chk user fullname
X Trent Trent J.
Larry Larry Smith
X Bob Bob Booth
X John John Smith
Where X is 1 from result set otherwise 0 is blank.

"Siemel Naran" <Si*********@REMOVE.att.net> wrote in message news:<aa*****************@bgtnsc04-news.ops.worldnet.att.net>...
"Trent" <tr*********@earthlink.net> wrote in message
Given a particular file_sid return all users with an extra column
(1,0) inticated whether or not there was a match in the file_access
table for given file_sid. here is what I attempted that DOES work in
mssql.


Would group by help? It's not exactly the same thing you're looking for,
but maybe can be tweaked.

select file.name, count(*)
from file
left outer join fileuser on file.id = fileuser.file_id
left outer join user on fileuser.user_id = user.id
group by file.name

If you really need 0, 1 then maybe there's another function you can use in
place of count(*). A simple if(...) or case comes to mind, but it has the
disadvantage of counting all the rows whereas you need to see if there is at
least one row (ie. stop counting at 1 row). So somewhere, somehow, a limit
1 might be helpful.

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: Brian Sabbey | last post by:
Here is a first draft of a PEP for thunks. Please let me know what you think. If there is a positive response, I will create a real PEP. I made a patch that implements thunks as described here....
31
by: da Vinci | last post by:
OK, this has got to be a simple one and yet I cannot find the answer in my textbook. How can I get a simple pause after an output line, that simply waits for any key to be pressed to move on? ...
6
by: deanfamily11 | last post by:
I've set up a case statement to have my program determine where on the Cartesian plane a point the user enters is located. I keep getting the C2051 error when I compile. Any help? #include...
1
by: PerryC | last post by:
Can someone help me accomplish the following in a MSAccess Report: 1. Check if Me.Discipline = "RN" (within the source query) 2. Then check the Me.YearOfEmployment: (again within the same source...
5
by: Rob Somers | last post by:
Hey all I am writing a program to keep track of expenses and so on - it is not a school project, I am learning C as a hobby - At any rate, I am new to structs and reading and writing to files,...
5
by: Tim::.. | last post by:
Can someone tell me how I convert this simple SQL statement so I can use it in ASP.NET??? I have an issue with the quotation marks and wondered if there is a simple rule for converting the sql...
12
by: rAinDeEr | last post by:
Hi, I have a table with 2 columns ** CREATE TABLE test (emp_num DECIMAL(7) NOT NULL,emp_name CHAR(10) NOT NULL) and i have inserted a number of records. ** Now, I want to insert a new...
26
by: jacob navia | last post by:
Summary: I have changed (as proposed by Chuck) the code to use isalpha() instead of (c>='a' && c <= 'z') etc. I agree that EBCDIC exists :-) I eliminated the goto statement, obviously it is...
4
by: amit.uttam | last post by:
Hey there, I have a simple question about python print statement. Take the following code snippet for example... 1 print "-#- executing: %s" % section, 2 tests =...
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
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...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
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.