Accessing Data in a SQL Query - sql

tell me how to make a user access to data access,
There is a table with dialogs, and you need to build a query so that another user cannot see this data if he does not have access to this dialog.
I tried to do it but it didn't work
SELECT *
FROM NameDS INNER JOIN
DialogueListDS ON NameDS.UserID = DialogueListDS.UserID INNER JOIN
MessegesListDS ON DialogueListDS.DialogueID = MessegesListDS.DialogueID
WHERE NameDS.UserID = '2B3F7596-DEC9-4CAF-A867-0127186CFC5C'

Related

"nested" table calls in JPA? (translate SQL to JPA)

I am trying to convert this SQL into a JPA #Query call, and am struggling to understand how to handle multiple table calls in one JPA Query, specifically i am trying to return a Count of all the Users that are assigned to a Program.
The DB structure is shown:
The query I want to translate is:
SELECT *FROM User WHERE id in ( SELECT user FROM UserProjectAssignment WHERE project in ( SELECT id FROM Project WHERE program = programId))
My current Query is:
#Query("SELECT COUNT(u) FROM User u, UserProjectAssignment upa, Project p WHERE u.id = upa.project AND WHERE upa.project = (p.program = :programId)")
Long countUsersAssignedToProgram(#Param("programId") Long programId);
Basically what you need here is query with JOIN s
But one can form the query only if he knows the class structures.
You can change the mysql query like this
Select user from User user join UserProjectAssignment upa on user.id = upa.userid join Project p on upa.projectId = p.id join program pgm on p.programId = pgm.id ;

Issue with Form's RecordSource: "This recordset is not updatable"

I'm having issues where I'm unable to update any fields in my form.
I'll get "This recordset is not updatable" when I try to modify some fields.
I had to working when I inner joined 2 tables on my Form's Record Source.
SELECT dbo_Menzits.*, dbo_CCC_Job.*
FROM dbo_Menzits
INNER JOIN dbo_CCC_Job ON dbo_Menzits.MenzitID = dbo_CCC_Job.ExternalId
However when i try to join another table it won't allow me to update the recordset (as shown below). I know Access has some rules that needs to be followed as specified Here but I'm unable to understand some of the rules.
All my tables are linked tables and they all have primary keys.
This is how i joined it:
SELECT dbo_Menzits.*, dbo_CCC_Job.*, dbo_jms_JobDetails.*
FROM (dbo_Menzits
INNER JOIN dbo_jms_JobDetails ON dbo_Menzits.MenzitID = dbo_jms_JobDetails.MenzitID)
INNER JOIN dbo_CCC_Job ON dbo_Menzits.MenzitID = dbo_CCC_Job.ExternalId

Updated MS Access table by joining other table not working

I'm trying to update an MS Access table by joining it to another table in another database and it's not working.
Here is the code I used:
UPDATE tbl_a a
INNER JOIN tbl_a b
IN '' [MS Access;PWD=Cb4XTNLq34c$;DATABASE=C:\data\memberdetails.mdb]
ON a.mobile=b.mobile
SET a.Mobilenew = b.Mobilenew,
a.isUpdated = 1,
a.Operator = b.Operator
WHERE b.isupdated=1
Can anyone see what I'm doing wrong?
What you should do is join the table to the database you're using. To do that, you should:
Click on "External Data" menu item on the top of Access
Click the Access icon
You're given a choice of importing or linking data. Choose "Link"
Browse and select the database containing the data you want to link (in your case, C:\data\memberdetails.mdb
You will be presented with a list of tables in the database. Choose which table(s) you want, and click OK
The new table will now exist in your database as a linked table. At that point, you can change your query to:
UPDATE tbl_a a
INNER JOIN tbl_a b
ON a.mobile=b.mobile
SET a.Mobilenew = b.Mobilenew,
a.isUpdated = 1,
a.Operator = b.Operator
WHERE b.isupdated=1
Since they're linked, any change that's made to tbl_a in either database will effect both databases, so just keep that in mind which you're working with it.

declare and use a string variable in oracle sql developer 4.1.3.20

So at work we've been using Oracle SQL Developer 4.1.3.20 lately to query our data so I wrote this snippet of code (its actually much longer by 8 or so more table joins):
select
s.NAME as "Shipment ID"
,k.STATUS_ID as "Status"
,u.SCR_NO as "SPID"
from xyz.DRUG_KIT k
left join xyz.DR_SHIP s on s.ID = k.SHIPMENT_ID
left join xyz.USR_PAT u on u.PAT_ID = k.PAT_ID
When I have to switch to another table in a different database, I have been copy pasting everywhere above where you see 'xyz' but surely there has to ba better way? I use to use SQL Server Management Studio 2014 but we had to switch to this once we began using oracle databases. How would I declare a varchar(?) variable in Oracle SQL Developer so I can just use that one variable in place of XYZ and at the top of the query I just can set that variable equal whatever necessary in one place if that makes sense. It becomes cumbersome when I copy paste something wrong on one line when I"m trying to join about 10+ tables together to retrieve data.
XYZ is the owner of the table, not a different database. If you are connected as user XYZ, then you don't need to prefix XYZ to the table name, it's only required if you are attempting to access objects owned by a different "SCHEMA".
You can change the current "parsing" schema of your session by issuing an alter session command:
ALTER SESSION SET CURRENT_SCHEMA=PDQ;
and then select from objects the user PDQ has granted you select privs on:
select
s.NAME as "Shipment ID"
,k.STATUS_ID as "Status"
,u.SCR_NO as "SPID"
from DRUG_KIT k
left join DR_SHIP s on s.ID = k.SHIPMENT_ID
left join USR_PAT u on u.PAT_ID = k.PAT_ID;
You can then alter your schema back to XYZ and perform the same select statement and get different results based on the contents of the tables as owned by XYZ:
ALTER SESSION SET CURRENT_SCHEMA=XYZ;
select
s.NAME as "Shipment ID"
,k.STATUS_ID as "Status"
,u.SCR_NO as "SPID"
from DRUG_KIT k
left join DR_SHIP s on s.ID = k.SHIPMENT_ID
left join USR_PAT u on u.PAT_ID = k.PAT_ID;
To make the DR_SHIP table owned by PDQ accessable from the XYZ schema, a private synonym to PDQ.DR_SIP can be created in place of the table onwed by XYZ:
CREATE OR REPLACE SYNONYM DR_SHIP FOR PDQ.DR_SHIP;
On the other hand if you want the PDQ version of the DRUG_KIT table accessible from all SCHEMAs in the DB, you can create a public synonym:
CREATE OR REPLACE PUBLIC SYNONYM DRUG_KIT FOR PDQ.DRUG_KIT;
If none of the above meet your needs, you can use SQL*Plus style substitution variables:
ACCEPT user;
select
s.NAME as "Shipment ID"
,k.STATUS_ID as "Status"
,u.SCR_NO as "SPID"
from &user..DRUG_KIT k
left join &user..DR_SHIP s on s.ID = k.SHIPMENT_ID
left join &user..USR_PAT u on u.PAT_ID = k.PAT_ID;
But you need to understand that these won't necessarily work outside of SQL*Plus, SQL Developer, SQLcl, and possibly a couple of other SQL development environments.
At the database level, you probably want public synonyms. https://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_7001.htm

Crystal Report Multiple data sources - Table Not Found

Using Crystal Reports version 13.0 in Visual Studio 2010.
Using the Command feature, all the fields needed are selected.
One of the fields is from a separate database on the same server.
SELECT r.ID, r.Revision,
u.FirstName + ' ' + u.LastName AS UpdateBy, r.UpdateDate,
s.Description AS Status, r.StatusID, r.Comments,
c.Notes
FROM Repel r
INNER JOIN Status s ON r.StatusID = s.id
INNER JOIN Conditions c ON c.SOCID = r.ID
LEFT OUTER JOIN [Admin].[dbo].[Users] u ON u.ID = r.UpdateBy
WHERE r.ID = {?item}
Using the database expert, both databases are connected but the command itself is on the main datasource.
The datasource with the tables Repel, Status, and Conditions.
It can NOT find the table Users.
The path is fully qualified so how can I get the report to see this table?
I know I could create a view in sql server itself and connect to that but there is a change that needs to be made to 30+ reports.
Thanks!!
EDIT
I tried to create a view in the main database only to use one datasource.
Then changed the line...
LEFT OUTER JOIN vUsers u ON u.ID = r.UpdateBy
Now I get the error:
This field name is not known.
Final EDIT
Doing more testing, I removed all database connections and fields from the report.
The unknown field name still appeared.
So, I removed everything from the report - still had the error.
Copied the text fields to a brand new report and added the database and command.
The error is now gone and the report is working.
Very strange.