Inner-join errors on SQL stored procedure - sql

I guess I'm just a bit weary, but the answer isn't jumping out for me right now. It throws an error
SQL Error [4145] [S0001]: An expression of non-boolean type specified in a context where a condition is expected, near 'WHERE'
Code:
ALTER PROCEDURE [dbo].[spDirectoryLookup]
(#LookupName nvarchar(100),
#ClientNumber bigint)
AS
BEGIN
SELECT DISTINCT
DL.subid,
C.ClientNumber,
C.ClientName,
listid,
dld.Description
FROM
INTELLIGENT_2414_1.DBO.dirListings DL
INNER JOIN
Intelligent_2414_1.DBO.cltClients C ON DL.subid = C.subid
INNER JOIN
INTELLIGENT_2414_1.DBO.dirListingDescriptions dld ON dld.listID
WHERE
Description LIKE '%'+#LookupName+'%'
AND DL.subid IN (SELECT subid
FROM Intelligent_2414_1.DBO.cltClients C
WHERE C.ClientNumber = #ClientNumber)
END

The second join's on clause is missing a condition. I'm guessing you meant to do this:
INNER JOIN INTELLIGENT_2414_1.DBO.dirListingDescriptions dld on dld.listID = DL.listid

Related

Sql pgadmin confused

The following query gives me a syntax error:
Select
traseu_stud.An,
traseu_stud.CodSpec
from
traseu_stud
where
NumePren = "Popescu W.T. Vasile"
and AnUniv = "2012-2013"
inner join studenti on traseu_stud.matricol = studenti.matricol
inner join persoane on studenti.idPers = persoane.idPers
ERROR: syntax error at or near "inner"
LINE 3: ...Pren="Popescu W.T. Vasile" and AnUniv="2012-2013" inner join...
^
SQL state: 42601
Character: 122
You have to use subquery if you want use filter in this way:
select * from
(
Select traseu_stud.An,traseu_stud.CodSpec,matricol
from traseu_stud
where NumePren='Popescu W.T. Vasile' and AnUniv='2012-2013'
) a
inner join studenti on a.matricol=studenti.matricol
inner join persoane on studenti.idPers=persoane.idPers
otherwise you have to use filter below way
Select traseu_stud.An,traseu_stud.CodSpec from
traseu_stud inner join
studenti on traseu_stud.matricol=studenti.matricol inner join persoane on
studenti.idPers=persoane.idPers
where NumePren='Popescu W.T. Vasile' and AnUniv='2012-2013'
The JOIN go into the from clause.
Additionally: String constants need to be enclose in single quotes, double quotes are for identifiers:
Select
traseu_stud.An,
traseu_stud.CodSpec
from traseu_stud
inner join studenti on traseu_stud.matricol = studenti.matricol
inner join persoane on studenti.idPers = persoane.idPers
where NumePren = 'Popescu W.T. Vasile'
and AnUniv = '2012-2013'
thank you for your help, but I have same errors, I put here the image with tables and what I want to do: What Specialization(Specializare) and in what Study year(AnUniv) it's the Popescu W.T. Vasile in 2012-2013.
https://i.stack.imgur.com/e1iV1.jpg

An expression of non-boolean type specified in a context where a condition is expected, near ')' error in IDT

While running the below code, I am getting error that says
an expression of non-boolean type specified in a context where a condition is expected, near ')'.
SELECT
OVUTCMN.FNCNL_LCTN_UE_DIM_TXT.LNG_CODE,
OVUTCMN.TNT_DIM.TNT_KEY,
OVUTCMN.TNT_DIM.TNT_CODE,
OVUTCMN.DATE_DIM.YY_NBR,
OVUTCMN.DATE_DIM.QTR_NBR,
'Q'+ CAST(OVUTCMN.DATE_DIM.QTR_NBR AS VARCHAR(10)) AS QTR_DESC,
OVUTCMN.DATE_DIM_TXT.MM_NBR,
OVUTCMN.DATE_DIM_TXT.MM_SHORT_DESC,
OVUTCMN.FNCNL_LCTN_UE_DIM_TXT.STD_ZONE_CODE,
OVUTCMN.FNCNL_LCTN_UE_DIM_TXT.STD_ZONE_NAME,
OVUTCMN.FNCNL_LCTN_UE_DIM_TXT.STD_SUBDVSN_CODE,
OVUTCMN.FNCNL_LCTN_UE_DIM_TXT.STD_SUBDVSN_NAME,
OVUTCMN.FNCNL_LCTN_UE_DIM_TXT.STD_UNIT_CODE,
OVUTCMN.FNCNL_LCTN_UE_DIM_TXT.STD_UNIT_NAME,
OVUTCMN.FALRE_TYPE_UE_DIM_TXT.FALRE_CTGRY_CODE,
OVUTCMN.FALRE_TYPE_UE_DIM_TXT.FALRE_CTGRY_DESC,
OVUTCMN.FALRE_TYPE_UE_DIM_TXT.STD_FALRE_TYPE_DESC,
OVUTCMN.FALRE_TYPE_UE_DIM_TXT.FR_CODE,
OVUTOI.OTG_STP_UE_F.INCDT_KEY,
OVUTOI.OTG_STP_UE_F.SRC_TYPE
FROM
OVUTCMN.FALRE_TYPE_UE_DIM_TXT INNER JOIN OVUTCMN.FALRE_TYPE_UE_DIM ON (OVUTCMN.FALRE_TYPE_UE_DIM_TXT.FALRE_TYPE_KEY=OVUTCMN.FALRE_TYPE_UE_DIM.FALRE_TYPE_KEY)
INNER JOIN OVUTOI.OTG_STP_UE_F ON (OVUTCMN.FALRE_TYPE_UE_DIM.FALRE_TYPE_KEY=OVUTOI.OTG_STP_UE_F.OUTAGE_KEY)
INNER JOIN OVUTCMN.TNT_DIM ON (OVUTOI.OTG_STP_UE_F.TNT_KEY=OVUTCMN.TNT_DIM.TNT_KEY)
INNER JOIN OVUTCMN.FNCNL_LCTN_UE_DIM_TXT ON (OVUTCMN.FNCNL_LCTN_UE_DIM_TXT.FNCNL_LCTN_KEY=OVUTOI.OTG_STP_UE_F.FNCNL_LCTN_KEY AND OVUTCMN.FNCNL_LCTN_UE_DIM_TXT.LNG_CODE = 'en_US')
INNER JOIN OVUTCMN.DATE_DIM ON (OVUTCMN.DATE_DIM.DATE_KEY=OVUTOI.OTG_STP_UE_F.PWR_RSTR_START_DATE_KEY)
INNER JOIN OVUTCMN.DATE_DIM_TXT ON (OVUTCMN.DATE_DIM.DATE_KEY=OVUTCMN.DATE_DIM_TXT.DATE_KEY AND OVUTCMN.DATE_DIM_TXT.DATE_KEY)
WHERE
(OVUTCMN.FALRE_TYPE_UE_DIM_TXT.LNG_CODE='en_US' AND OVUTCMN.FALRE_TYPE_UE_DIM_TXT.FALRE_CTGRY_CODE<>9
AND OVUTCMN.DATE_DIM.YY_NBR BETWEEN DATEPART(YYYY,DATEADD(YYYY,-2,GETDATE())) and DATEPART(YYYY,GETDATE()) )
GROUP BY
OVUTCMN.FNCNL_LCTN_UE_DIM_TXT.LNG_CODE,
OVUTCMN.TNT_DIM.TNT_KEY,
OVUTCMN.TNT_DIM.TNT_CODE,
OVUTCMN.DATE_DIM.YY_NBR,
OVUTCMN.DATE_DIM.QTR_NBR,
OVUTCMN.DATE_DIM_TXT.MM_NBR,
OVUTCMN.DATE_DIM_TXT.MM_SHORT_DESC,
OVUTCMN.FNCNL_LCTN_UE_DIM_TXT.STD_ZONE_CODE,
OVUTCMN.FNCNL_LCTN_UE_DIM_TXT.STD_ZONE_NAME,
OVUTCMN.FNCNL_LCTN_UE_DIM_TXT.STD_SUBDVSN_CODE,
OVUTCMN.FNCNL_LCTN_UE_DIM_TXT.STD_SUBDVSN_NAME,
OVUTCMN.FNCNL_LCTN_UE_DIM_TXT.STD_UNIT_CODE,
OVUTCMN.FNCNL_LCTN_UE_DIM_TXT.STD_UNIT_NAME,
OVUTCMN.FALRE_TYPE_UE_DIM_TXT.FALRE_CTGRY_CODE,
OVUTCMN.FALRE_TYPE_UE_DIM_TXT.FALRE_CTGRY_DESC,
OVUTCMN.FALRE_TYPE_UE_DIM_TXT.STD_FALRE_TYPE_DESC,
OVUTCMN.FALRE_TYPE_UE_DIM_TXT.FR_CODE,
OVUTOI.OTG_STP_UE_F.INCDT_KEY,
OVUTOI.OTG_STP_UE_F.SRC_TYPE
HAVING max(coalesce(B.SRC_PWR_RSTR_DURTN,0))>=0
The problem is in your last ON clause:
INNER JOIN OVUTCMN.DATE_DIM_TXT ON
(
OVUTCMN.DATE_DIM.DATE_KEY = OVUTCMN.DATE_DIM_TXT.DATE_KEY
AND OVUTCMN.DATE_DIM_TXT.DATE_KEY
)

SUB SELECT QUERY WITH INNER JOIN giving Unexpected results

This is my query inside my stored procedure
DECLARE #branch uniqueidentifier
SELECT #branch = Branch_Id
FROM Student_Master
WHERE Student_Id = #studentid
SELECT
CompanyMaster.unique_id_company,
Job_College.College_Id,
Job_Branch.Branch_Id,
CompanyMaster.name,
Job_Master.Job_Post_Date, Job_Master.Job_Title,
Job_Master.Salary, Job_Master.Job_Location,
Department_Master.Department_Name
FROM
Job_Master
INNER JOIN
Company_Master ON Job_Master.Company_ID = CompanyMaster.unique_id_company
INNER JOIN
Department_Master ON Department_Master.Department_Id = Job_Master.Department_Id
INNER JOIN
Job_College ON Job_Master.Job_ID = Job_College.Job_Id
INNER JOIN
Job_Branch ON Job_Branch.Job_College_ID = Job_College.Job_College_ID
WHERE
Job_Branch.Branch_Id = #branch
Logically query is correct and is producing expected results if I pass value of #branch directly to it (instead of using SELECT query in the beginning) but with this method shown in code by populating value of #branch with select query at the beginning, this query results 0 results although #branch is receiving value from it.
Things I have tried
Using SELECT query directly inside WHERE clause
I have seen that PRINT #branch gives right output so it should work in WHERE clause but it is not working
Please help!! I am stuck for past many hours

Oracle ORA:00904: Subquery in LEFT JOIN

I'm aware of the subquery limitations of Oracle's ANSI SQL setup. You can't use an identifier in a subquery that is declared more than one level deep.
I'm attempting the following query, which as far as I can see is only one level deep, but I'm getting this error. Does this not work for table joins? (I've truncated the procedure somewhat, but the problem should be clear. Additionally, if it means anything, I'm using FIRST_VALUE analytic functions in my select values. We're on 10g.)
The error:
Error(111,79): PL/SQL: ORA-00904: "VT"."MAIL_TO_ADDRESS_NUMBER": invalid identifier
The proc:
PROCEDURE MYPROCEDURE (
p_TransactionId IN NUMBER,
p_Cursor_Out OUT SYS_REFCURSOR
)
AS
BEGIN
OPEN p_Cursor_Out FOR
SELECT
...
FROM vehicle_transaction vt
INNER JOIN registration_transaction reg ON vt.transaction_id = reg.transaction_id
/* The problem is here */
LEFT OUTER JOIN (
SELECT
laddt2.address
FROM lien_address_transaction laddt2
WHERE vt.mail_to_address_number IS NOT NULL AND laddt2.address_number = vt.mail_to_address_number
) laddt
ON (laddt2.address_number = vt.mail_to_address_number)
WHERE vt.transaction_id = p_TransactionId;
END MYPROCEDURE;
You are trying to do a lateral join. You cannot use an external table alias in the from clause. In general, the work-around is to use aggregation:
SELECT
...
FROM vehicle_transaction vt INNER JOIN
registration_transaction reg
ON vt.transaction_id = reg.transaction_id LEFT OUTER JOIN
(SELECT laddt2.address_number, MIN(laddt2.address) as address
FROM lien_address_transaction laddt2
WHERE vt.mail_to_address_number IS NOT NULL AND
GROUP BY laddt2.address_number
) laddt
ON laddt.address_number = vt.mail_to_address_number
WHERE vt.transaction_id = p_TransactionId;

Can Derby handle scalar subqueries in SELECT clause?

I'm having trouble getting my query working. Could someone cast an experienced eye on it please? The table structure is simple (2 one-to-many relationships). The query is trying to work out for each sign, how many contributions there are at each unique "PositionLocation".
Sign <- Signifier (f_key sign_oid) <- Contribution (f_key signifier_oid)
I'm getting the following error:
Error: An ON clause associated with a JOIN operator is not valid.
SQLState: 42972
ErrorCode: -1
My query is:
select s.NAME, c.POSITIONLOCATION, count(*) as num_per_locn,
(
select count(*) from APP.CONTRIBUTION c2
inner join APP.SIGNIFIER si2 on si2.OID = c2.SIGNIFIER_OID
inner join APP.SIGN s2 on s2.OID = si2.SIGN_OID
and s2.OID = s.OID
) as num_per_sign
from APP.CONTRIBUTION c
inner join APP.SIGNIFIER si on si.OID = c.SIGNIFIER_OID
inner join APP.SIGN s on s.OID = si.SIGN_OID
group by s.NAME, c.POSITIONLOCATION