multipart Identifier cound not be bound - sql

I reviewed several of the post on this subject and haven't been able to see resolve this error. I have linked server that I'm trying to included in my WHERE clause in SQL 2008. I was able to successfully execute the query with out the WHERE clause. I'm sure that I overlooked something just need some advice. The message for the multipart identifier is on this line in the WHERE clause.
LAWNURSEDB.NGDemo.dbo.EXPORT_DIRECTTIME.SocialSecurityNumber
SELECT dbo.VP_PUNCHORIGIN.PERSONNUM, EXPORT_DIRECTTIME_1.SocialSecurityNumber, dbo.VP_PUNCHORIGIN.PERSONFULLNAME
FROM dbo.VP_PUNCHORIGIN INNER JOIN
LAWNURSEDB.NGDemo.dbo.EXPORT_DIRECTTIME AS EXPORT_DIRECTTIME_1 ON
dbo.VP_PUNCHORIGIN.PERSONNUM = EXPORT_DIRECTTIME_1.SocialSecurityNumber
WHERE (dbo.VP_PUNCHORIGIN.PERSONNUM NOT IN
(SELECT LAWNURSEDB.NGDemo.dbo.EXPORT_DIRECTTIME.SocialSecurityNumber AS Expr1
FROM LAWNURSEDB.NGDemo.dbo.EXPORT_DIRECTTIME AS EXPORT_DIRECTTIME_1))

You are using an alias in the WHERE clause subquery but don't reference it:
SELECT p.PERSONNUM,
EXPORT_DIRECTTIME_1.SocialSecurityNumber,
p.PERSONFULLNAME
FROM dbo.VP_PUNCHORIGIN p
INNER JOIN LAWNURSEDB.NGDemo.dbo.EXPORT_DIRECTTIME AS EXPORT_DIRECTTIME_1
ON p.PERSONNUM = EXPORT_DIRECTTIME_1.SocialSecurityNumber
WHERE p.PERSONNUM
NOT IN (SELECT EXPORT_DIRECTTIME_2.SocialSecurityNumber
FROM LAWNURSEDB.NGDemo.dbo.EXPORT_DIRECTTIME AS EXPORT_DIRECTTIME_2)

Related

Outer join for Alias name and column name -Oracle

I had a working sample query earlier in my code as mentioned below.
SELECT DISTINCT
nombre_aplicacion,
APLICACION,
NOMBRE_APLCODE,
DESCRIPCION,
AREAFUNC
FROM (
select **CODAPLICATION nombre_aplicacion**,
APLICACION,
NOMBRE_APLCODE,
DESCRPTION,
AREAFUNC
from admin.VW_APLICACIONES#dblink,
admin.VW_PRODUCTOS#dblink
where **nombre_aplicacion (+) = CODAPLICATION**
)
WHERE 1=1
ORDER BY nombre_aplicacion ASC;
When I try similar type of query with different tables I was getting error as invalid ORA-00904: "NOMBRE_APLICACION": invalid identifier.
If I remove nombre_aplicacion (+) = CODAPLICATION in where condition query is fetching the result. Can any one suggest why I was facing error as its working earlier with sample query and I was getting error? Is this join is valid?
The query is not valid as:
In the inner sub-query you select areafunc and in the outer query you use area which does not appear in the inner sub-query so will not be available.
In the inner sub-query, you define CODAPLICATION to have the alias nombre_aplicacion and then you try to use that alias in the WHERE clause as a join condition; that will not work.
You have not described which column belongs to which table but you want something like:
SELECT DISTINCT
a.codaplication AS nombre_aplicacion,
a.aplicacion,
a.nombre_aplcode,
p.descrption,
p.areafunc
from APLICACIONES a
LEFT OUTER JOIN PRODUCTOS p
ON (a.primary_key_column = p.foreign_key_column)
ORDER BY nombre_aplicacion ASC;
Note: you are going to have to correct the code to give the correct table aliases for each column and give the correct columns for the join condition.

"Multi-part identifier cannot be bound" in Crystal Reports with SQL Expressions/Subqueries

I'm using Crystal Reports, which enables you to create things called SQL Expressions. They are basically subqueries, but limited so that each SQL Expression can only return a scalar value. For more info, here: http://www.cogniza.com/wordpress/2005/11/07/crystal-reports-using-sql-expression-fields/
The referenced article says very specifically that:
If you are using a SQL Expression as a subquery and wish to link it to the
detail row of your main report, do not include the table you wish to link to
in the FROM clause of the subquery. For example:
(
SELECT MAX("FLOWSHEET"."VALUE")
FROM FLOWSHEET
WHERE "FLOWSHEET"."ID" in ('11')
AND "FLOWSHEET"."IP_ID" = "HOSPITAL_VISIT"."IP_ID"
)
The above query links to the HOSPITAL_VISIT table in the main report by
linking to the IP_ID field. To accomplish this, HOSPITAL_VISIT is omitted
from the FROM clause in the query.
I have a main query in my report that says:
SELECT
hp.MovedInDate,
c.LastName,
c.FirstName,
chp.ClientID
FROM
chp
INNER JOIN hp ON chp.HousePlacementID = hp.HousePlacementID
INNER JOIN c ON chp.ClientID = c.ClientID
Now I want to add a SQL Expression
(
SELECT TOP 1 AssessmentAcuityType
FROM a
WHERE a.ClientID = chp.ClientID
AND a.AssessmentTool = 'SPDAT'
AND a.AssessmentToolType NOT LIKE '%VI%'
AND a.IntakeDate BETWEEN DATEADD(month,-6,hp.MovedInDate) AND hp.MovedInDate
ORDER BY IntakeID DESC
)
When I do so, I get the error The multi-part identifier hp.MovedInDate cannot be bound
So although I know I didn't define hp in my subquery, the rules of SQL Expression fields state that I shouldn't. Anyone able to help me understand how to fix this error?
I have solved part of the problem.
Part of the problem relies on the order of the sides of the equation.
So I've determined that this results in an error:
(
SELECT TOP 1 AssessmentAcuityType
FROM a
WHERE a.ClientID = chp.ClientID
)
And this does not
(
SELECT TOP 1 AssessmentAcuityType
FROM a
WHERE chp.ClientID = a.ClientID
)

MS Access error, aggregate function

I am trying to run the sql query below in access. I keep getting the MS Access error:
"You tried to execute a query that does not include the specified expression 'ID' as part of an aggregate function"
The query I wrote is as below:
SELECT Subject.ID, Subject.Description, Max(DataSets.ID) AS ID_DataSets
FROM Subject
INNER JOIN DataSets ON Subject.Description = DataSets.Subject.Value
GROUP BY Subject.ID, Subject.Description;
I see an error in this reference DataSets.Subject.Value, but I'm not sure it would generate that error message. Try this version:
SELECT s.ID, s.Description, Max(ds.ID) AS ID_DataSets
FROM Subject as s INNER JOIN
DataSets as ds
ON s.Description = ds.Value -- is this correct?
GROUP BY s.ID, s.Description;
I find queries easier to write and read when they use table aliases.

Oracle Invalid Identifier ORA-00904

I keep getting this error trying to run this simple Join.....
SELECT docregitem.reviewdate, docregitem.nclient, client.name
FROM docregitem, client
INNER JOIN client
ON docregitem.nclient = client.nclient
ORA-00904: "DOCREGITEM"."NCLIENT": invalid identifier
I can do a select and all the columns are present and correct...
I think the query you want is:
SELECT dr.reviewdate, dr.nclient, c.name
FROM docregitem dr INNER JOIN
client c
ON dr.nclient = c.nclient;
Your from clause has a comma in it. This is a lot like a cross join, but it affects the columns. These are not known in the on clause, which is what is causing the problem.
SELECT docregitem.reviewdate, docregitem.nclient, client.name
FROM docregitem
INNER JOIN client
ON docregitem.nclient = client.nclient
you try this one as you used client table twice one with simple join and other with inner join without giving the alias name to the table so the compiler is confused in selecting and comparing column from client table.

Nested query issue, Invalid Identifier error

I am running following query in Oracle 10 XE and getting [Err] ORA-00904: "Q": invalid identifier
SELECT questions.sb_title Q,questions.sb_baab_id,questions.sb_fasal_id,QUESTIONS.SB_CONTENT answer,IST.SB_PREFERENCE PREF
FROM USER_QUESTIONS questions
INNER JOIN USER
ON QUESTIONS.SB_USER_ID = USER.SB_ID
INNER JOIN IST
ON IST.SB_ID = USER.SB_IST_ID
AND(Q LIKE '%where is%')
AND USER.SB_IST_ID =
(
Select issued.SB_IST_ID
FROM USER_REGISTER register_number
INNER JOIN USER_ISSUED issued
ON register_number.SB_REGISTER_NUMBER = ISSUED.SB_REGISTER_NUMBER
AND REGISTER_NUMBER.SB_REGISTER_NUMBER IN(1240)
)
You cannot reference an alias in the JOIN condition - write the actual column name: sb_title.
I don't think you can use the alias "Q" like that. You're aliasing it in your select clause, don't think you can use that alias in your ON clause. Try using the full column name (sb_title).