473,659 Members | 3,592 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.use r_sid from file_access
where file_access.fil e_sid=1 and file_access.use r_sid=user.user _sid)
is null then 1 else 0 end as has_access, user.* from user
PLEASE HELP...
Jul 20 '05 #1
2 1630
"Trent" <tr*********@ea rthlink.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_i d
left outer join user on fileuser.user_i d = 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*********@RE MOVE.att.net> wrote in message news:<aa******* **********@bgtn sc04-news.ops.worldn et.att.net>...
"Trent" <tr*********@ea rthlink.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_i d
left outer join user on fileuser.user_i d = 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
2373
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. It is available at: http://staff.washington.edu/sabbey/py_do Good background on thunks can be found in ref. . Simple Thunks
31
14328
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? Basically: "Press any key to continue..." I beleive that I am looking for is something along the lines of a....
6
4695
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 <iomanip> #include <iostream> using namespace std;
1
1607
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 query) if <2 then Me.BaseRate = BaseRate, if between 2 and <5 then Me.BaseRate = BaseRate * 1.03 if between 5 and <10 then Me.BaseRate = BaseRate * 1.03 * 1.03 ....
5
7235
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, two aspects which I want to incorporate into my program eventually. That aside, my most pressing problem right now is how to get rid of the newline in the input when I use fgets(). Now I have looked around on the net, not so much in this group...
5
1730
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 statement so if can be used in ASP.NEt! Thanks ... SQL String
12
21075
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 record (3232,'Raindeer') based on the condition that the
26
495
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 better in a tutorial to stick to structured programming whenever possible...
4
1236
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 = test.testcase(name=config.get(section,'name')) 3 tests.runTest() 4 printStatus(tests)
0
8337
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8531
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8628
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7359
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2754
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.