There are
*= and =*
sql equalities in my application queries. What does it mean? I have investigated on google but i could not find sufficient information. For example :
SELECT ODR_YO_ID, OGR_OKUL_NO, OGR_ADI+' '+OGR_SOYADI OGR, COUNT(ODR_YO_ID) SAYI
FROM OGRENCI,YIL_SUBE,YIL_OGRENCI, OGRENCI_DAVRANIS
WHERE ODR_OLUMLU = 1 AND YO_OGR_ID = OGR_ID AND ODR_YO_ID = YO_ID AND YO_AKTIF = 1 AND
YO_YSB_ID = YSB_ID AND YSB_ID = 2183 AND YSB_YIL_KOD *= ODR_YIL_KOD AND ODR_OGR_ID =* OGR_ID
GROUP BY ODR_YO_ID, OGR_OKUL_NO, OGR_ADI+' '+OGR_SOYADI, YO_OKUL_DEGIS_TARIHI
ORDER BY OGR
When i execute this sql query in my local computer, i take this error:
Msg 102, Level 15, State 1, Line 5
Incorrect syntax near '*='.
But i run same query in related server, this query works without any error.I use sql server 2012 express edition in my local computer and there is sql server 2005 in related server. Why ?
Thanks in advance.
*= was the ANSI-89 syntax for a left join. It is now deprecated which is why you get the error.
Similarly =* is analogous to right join.
You need to move the join clauses from the where clause to the join syntax, but without knowing which tables the fields come from, I can't be more specific
ie
YSB_YIL_KOD *= ODR_YIL_KOD
becomes
ysbtable
left join odrtable
on YSB_YIL_KOD = ODR_YIL_KOD
and
ODR_OGR_ID =* OGR_ID
becomes
odrtable
right join ogrtable
on ODR_OGR_ID = OGR_ID
You may be able to make the query work on your local machine by changing the database compatibility level ( http://technet.microsoft.com/en-us/library/bb510680.aspx ) but I would advise rewriting it to the current syntax.
Related
I'm new here specifically for this problem...I already search every topic and none has helped me so far.
I am trying to create a little report but the error that "could not be bound" is hunting me.
select i.ins_serial_number AS "Serial",
t.tag_tag AS "TAG",
tg.tcv_strategy_id_ck AS "Estrategia",
tg.tcv_cal_value AS "Valor",
tg.tcv_error_tolerance as "Crit Aceit",
un.un_unit as "Unidade"
from tag_cal_values as tg,
units as un,
tags as t,
inst_scales as sc
left outer join instruments as i
on i.ins_instrument_id_pk = t.tag_instrument_id_fk
where t.tag_tag_id_pk = tg.tcv_tag_id_ck
and un.un_unit_id_pk = sc.isc_input_unit_id_fk
message 4104, level 16, state 1, line 1
The multi-part identifier "t.tag_instrument_id_fk" could not be bound.
The column name, table, etc is all okay.
obs: actuall I'm not expert in SQL, so...
I'm running this query in SQL Server Management Studio 2008.
Thanks :)
Never use commas in the FROM clause. Always use proper, explicit, standard JOIN syntax:
from tags t JOIN
tag_cal_values tg
on t.tag_tag_id_pk = tg.tcv_tag_id_ck cross join
units un join
inst_scales as sc
un.un_unit_id_pk = sc.isc_input_unit_id_fk left join
instruments as i
on i.ins_instrument_id_pk = t.tag_instrument_id_fk
This will fix the syntax problem. I doubt this does anything useful, though. It looks like you are missing one or more join conditions.
From what I can tell tags is trying to use the fk from instruments to join in with the rest of the tables. Since instruments comes later in the query it is messing it up. For future reference you really should not be mixing your join styles, I personally like doing INNER JOIN, LEFT OUTER JOIN etc for every table I am using.
I have a SQL query written in SQL Server version 2000. The query is not running in SQL Server 2016. The query is like below.
Select *
from ProjPace2 P, ProjPace2 P2
where P.DivCode *= P2.DivCode
and P.ProjGrp *= P2.ProjGrp
and P.ProjYr *= P2.ProjYr
and P.T_D *= P2.T_D
and P.Qtr *= P2.Qtr
and P.SRA_LRA *= P2.SRA_LRA
and P.District *= P2.District
and P.PICompany *= P2.PICompany
and P.ContCode *= P2.ContCode
and P.dtWkEnding > dateadd(dd,-1,'1/1/2015')
and P2.dtWkEnding between dateadd(dd,-10,'1/1/2015') and dateadd(dd,-3,'1/1/2015')
I am getting the following error:
Msg 4147, Level 15, State 1, Line 20
The query uses non-ANSI outer join operators ("*=" or "=*"). To run this query without modification, please set the compatibility level for current database to 80, using the SET COMPATIBILITY_LEVEL option of ALTER DATABASE. It is strongly recommended to rewrite the query using ANSI outer join operators (LEFT OUTER JOIN, RIGHT OUTER JOIN). In the future versions of SQL Server, non-ANSI join operators will not be supported even in backward-compatibility modes.
I can understand the error is occurring due to "*" and I want to replace it with Left outer join so I can get the same result.
Any help will be thankfully accepted.
Partha
All conditions that are specified with *= operator denote ON clause for LEFT OUTER JOIN. So equivalent query would become:
Select *
from ProjPace2 P
left outer join ProjPace2 P2 on
P.DivCode = P2.DivCode
and P.ProjGrp = P2.ProjGrp
and P.ProjYr = P2.ProjYr
and P.T_D = P2.T_D
and P.Qtr = P2.Qtr
and P.SRA_LRA = P2.SRA_LRA
and P.District = P2.District
and P.PICompany = P2.PICompany
and P.ContCode = P2.ContCode
where P.dtWkEnding > dateadd(dd,-1,'1/1/2015')
and P2.dtWkEnding between dateadd(dd,-10,'1/1/2015') and dateadd(dd,-3,'1/1/2015')
One note though: Since you have condition where returned rows must have P2.dtWkEnding between dateadd(dd,-10,'1/1/2015') and dateadd(dd,-3,'1/1/2015') there is no need for LEFT OUTER JOIN since rows without matching P2 record will never be returned. So for this query you should use INNER JOIN.
As a beginner to Google's BigQuery platform, I have found it almost similar to MySql regarding its syntax. However, I am receiving an issue with my query where it is not finding a column on either side of the Inner Join I am performing.
A sample query below:
SELECT
base_account.random_table_name_transaction.context_id,
base_account.random_table_name_transaction.transaction_id,
base_account.random_table_name_transaction.meta_recordDate,
base_account.random_table_name_transaction.transaction_total,
base_account.random_table_name_transaction.view_id,
base_account.random_table_name_view.user_id,
base_account.random_table_name_view.view_id,
base_account.random_table_name_view.new_vs_returning,
base_account.random_table_name_experience.view_id,
base_account.random_table_name_experience.experienceId,
base_account.random_table_name_experience.experienceName,
base_account.random_table_name_experience.variationName,
base_account.random_table_name_experience.iterationId,
base_account.random_table_name_experience.isControl
FROM
[base_account.random_table_name_transaction] transactiontable
INNER JOIN
base_account.random_table_name_view viewtable
ON
transactiontable.view_id=viewtable.view_id
INNER JOIN
[base_account.random_table_name_experience] experiencetable
ON
viewtable.view_id=experiencetable.view_id
WHERE experiencetable.experienceId = 96659 or experiencetable.experienceId = 96660
In this case, when I run it within the BigQuery platform, after a few seconds of the query running I am returned an error:
"Error: Field 'base_account.random_table_name_experience.experienceId' not found on either side of the JOIN".
However, when I run the same query however I perform a SELECT * query, it does execute properly and returns the data I expect.
Is there something missing with my syntax as to why it is failing? I can confirm that each column I am trying to return does exist in each respected table.
Make sure to use standard SQL for your query to avoid some of the surprising aliasing rules with legacy SQL and to get more informative error messages. Your query would be:
#standardSQL
SELECT
base_account.random_table_name_transaction.context_id,
base_account.random_table_name_transaction.transaction_id,
base_account.random_table_name_transaction.meta_recordDate,
base_account.random_table_name_transaction.transaction_total,
base_account.random_table_name_transaction.view_id,
base_account.random_table_name_view.user_id,
base_account.random_table_name_view.view_id,
base_account.random_table_name_view.new_vs_returning,
base_account.random_table_name_experience.view_id,
base_account.random_table_name_experience.experienceId,
base_account.random_table_name_experience.experienceName,
base_account.random_table_name_experience.variationName,
base_account.random_table_name_experience.iterationId,
base_account.random_table_name_experience.isControl
FROM
`base_account.random_table_name_transaction` transactiontable
INNER JOIN
base_account.random_table_name_view viewtable
ON
transactiontable.view_id=viewtable.view_id
INNER JOIN
`base_account.random_table_name_experience` experiencetable
ON
viewtable.view_id=experiencetable.view_id
WHERE experiencetable.experienceId = 96659 OR experiencetable.experienceId = 96660;
Note that the only changes I made were to put the #standardSQL at the start (to enable standard SQL) and to escape the table names with backticks rather than brackets.
When I execute the query below I get the following error message :
ORA-00918: column ambigously defined
ORA-02063: preceding line from ABC
Query:
SELECT
dos.*,
cmd.*,
cmd_r.*,
adr_inc.*,
adr_veh.*,
loc.*,
fou_d.*,
fou_r.*, --Works if I comment this line
mot.*
FROM
DOSSIERS#ABC dos
LEFT JOIN CMDS#ABC cmd ON cmd.DOS_CODE_ID = dos.dos_code_id
LEFT JOIN CMDS_RECCSTR#ABC cmd_r ON cmd_r.DOS_CODE_ID = dos.DOS_CODE_ID AND cmd_r.CMD_CODE_ID = cmd.CMD_CODE_ID AND cmd_r.CMD_DT_CREAT = cmd.CMD_DT_CREAT
LEFT JOIN HISTO_ADR#ABC adr_inc ON adr_inc.DOS_CODE_ID = dos.DOS_CODE_ID
LEFT JOIN HISTO_ADR#ABC adr_veh ON adr_veh.DOS_CODE_ID = dos.DOS_CODE_ID
LEFT JOIN LOC#ABC loc ON dos.DOS_CODE_ID = loc.DOS_CODE_ID
LEFT JOIN FOURNISS#ABC fou_d ON fou_d.PAY_CODE_ID = loc.PAY_CODE_ID_D AND fou_d.FOU_CODE_ID = loc.FOU_CODE_ID_D
LEFT JOIN FOURNISS#ABC fou_r ON fou_r.PAY_CODE_ID = loc.PAY_CODE_ID_R AND fou_r.FOU_CODE_ID = loc.FOU_CODE_ID_R
LEFT JOIN REF_MOT#ABC mot ON mot.RMR_CODE_ID = cmd_r.RMR_CODE_ID
WHERE
dos.REF_EXT = 'XXXXXXX'
If I comment fou_r.* in SELECT it works.
The following queries don't work neither:
SELECT *
FROM ... ;
SELECT (SELECT count(xxx) FROM ...)
FROM ...;
I looked at similar issues on SO but they were all using complex queries or was using many SELECT inside WHERE. Mine is simple that is why I don't understand what could be wrong.
Current Database: Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
Target Database (refers to db link ABC target): Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
Client: Toad for Oracle 9.7.2.5
You seem to be hitting bug 13589271. I can't share details from MOS, but there isn't much to share anyway. It's related to the remote table having a column with a 30-character name though, as you have in your remote FOURNIUSS table.
Unfortunately simply aliasing the column in your query, like this:
fou_d.COLUMN_WITH_30_CHARACTERS_NAME alias_a,
fou_r.COLUMN_WITH_30_CHARACTERS_NAME alias_b,
... doesn't help and still gets the same error, as the alias is applied by the local database and the problem seems to be during the remote access. What does seem to work is using an in-line view to apply a column alias before the join:
...
LEFT JOIN LOC#ABC loc ON dos.DOS_CODE_ID = loc.DOS_CODE_ID
LEFT JOIN (
SELECT PAY_CODE_ID, FOU_CODE_ID, COLUMN_WITH_30_CHARACTERS_NAME alias_a FROM FOURNISS#ABC
) fou_d ON fou_d.PAY_CODE_ID = loc.PAY_CODE_ID_D AND fou_d.FOU_CODE_ID = loc.FOU_CODE_ID_D
LEFT JOIN (
SELECT PAY_CODE_ID, FOU_CODE_ID, COLUMN_WITH_30_CHARACTERS_NAME alias_b FROM FOURNISS#ABC
) fou_r ON fou_r.PAY_CODE_ID = loc.PAY_CODE_ID_R AND fou_r.FOU_CODE_ID = loc.FOU_CODE_ID_R
LEFT JOIN REF_MOT#ABC mot ON mot.RMR_CODE_ID = cmd_r.RMR_CODE_ID
...
This even works if you give the column the same alias in both inline views. The downside is that you have to explicitly list all of the columns from the table (or at least those you're interested in) in order to be able to apply the alias to the problematic one, but having done so you can still use fou_d.* and fou_r.* in the outer select list.
I don't have an 11.2.0.2 database but I've run this successfully in an 11.2.0.3 database which still showed the ORA-00918 error from your original code. It's possible something else in 11.2.0.2 will stop this workaround being effective, of course. I don't see the original problem in 11.2.0.4 at all, so upgrading to that terminal patch release might be a better long-term solution.
Using * is generally considered a bad practice anyway though, not least because you're going to get a lot of duplicated columns from the joins (lots of dos_code_id in each row, for example); but you're also likely to be getting other data you don't really want, and anything that consumes this result set will have to assume the column order is always the same in those tables - any variation, or later addition or removal of a column, will cause problems.
I am running the below SELECT statement to:
Return prices from a standard price list customer = 0
If the customer has been quoted a special price customer = X then use that price instead
I am getting the error message:
ERROR at line 3:
ORA-00933: SQL command not properly ended
Oracle version is: Oracle8i Enterprise Edition Release 8.1.7.4.0 - Production.
SELECT glas_daten_basis.idnr, glas_daten_basis.gl_bez, NVL(p2.zum2, p1.zum2)
FROM glas_daten_basis
JOIN os_przu p1 ON p1.idnr = glas_daten_basis.idnr
LEFT JOIN os_przu p2 ON p2.idnr = glas_daten_basis.idnr AND p2.kunr = 63
WHERE p1.kunr = 0;
Line 3 is the JOIN, is there something wrong here?
Update: There are 137 rows in the standard price list, so I should be given 137 rows regardless of whether the price is from customer = 0 or customer = X. The answers so far give me a ~60 rows for some reason.
SELECT os_przu.idnr, os_przu.zum2
FROM os_przu
WHERE os_przu.kunr = 0;
...
137 rows selected.
As #a_horse-with_no_name said, ANSI joins don't work in 8i; they weren't added until 9i. So if you're really stuck on this ancient and unsupported version you're stuck with the old Oracle-specific syntax:
SELECT glas_daten_basis.idnr, glas_daten_basis.gl_bez, NVL(p2.zum2, p1.zum2)
FROM glas_daten_basis, os_przu p1, os_przu p2
WHERE p1.idnr = glas_daten_basis.idnr
AND p1.kunr = 0
AND p2.idnr (+) = glas_daten_basis.idnr
AND p2.kunr (+) = 63;
Which is pretty similar to #nelucon's answer, except that only had one (+) left-join marker and it was on the wrong side of the condition.
SQL Fiddle.
The (+) is the Oracle-specific outer-join operator, and it has to be applied to each condition for the outer-joined table - if one is missed then the rest are ignored and it effectively becomes an inner join again. (One of the reasons ANSI joins are easier to work with, though you can still get that wrong by referring to the joined table in the where clause as well as the on.)
something like this, i didn't test the code but you got it. (+) means the left join. for more infos, google for "oracle 8 left join"
SELECT glas_daten_basis.idnr, glas_daten_basis.gl_bez, NVL(p2.zum2, p1.zum2)
FROM glas_daten_basis, os_przu p1, os_przu p2
WHERE p1.kunr = 0
AND p1.idnr = glas_daten_basis.idnr
AND p2.idnr = glas_daten_basis.idnr (+)
AND p2.kunr = 6;