Toon posts:

Foute query in SQL server

Pagina: 1
Acties:

Verwijderd

Topicstarter
Ik probeer een query uit te voeren in SQL Server, maar ik krijg steeds de foutmelding: Incorrect syntax near the keyword 'INNER'.

Wat is er fout aan de query hieronder :?
code:
1
2
3
4
5
6
7
8
9
update tblBewoner INNER join tblMutatie_BewonerMutaties ON  [tblBewoner.Bewoner_ID] = [tblMutatie_BewonerMutaties.Bewoner_ID]
INNER JOIN nslMutatie_MutatieType ON tblMutatie_BewonerMutaties.MutatieType_ID = nslMutatie_MutatieType.ID 
SET tblBewoner.Afdeling_ID = [tblMutatie_BewonerMutaties].[Afdeling_ID], tblBewoner.Kamer = [tblMutatie_BewonerMutaties].[Kamer] 
WHERE (((nslMutatie_MutatieType.IsVerblijfsLokatie)=true) 
  AND ((tblMutatie_BewonerMutaties.BeginDatum)<=getDate()) 
    AND ((tblMutatie_BewonerMutaties.EindDatum) Is Null 
    Or (tblMutatie_BewonerMutaties.EindDatum)>=getDate()) 
     AND ((tblMutatie_BewonerMutaties.MutatieSoort)=1 
       Or (tblMutatie_BewonerMutaties.MutatieSoort)=2))

Verwijderd

Volgens mijn handleiding moet INNER JOIN pas na de FROM en niet na de UPDATE...

[edit]:
code:
1
2
3
4
5
UPDATE titles
    SET ytd_sales = t.ytd_sales + s.qty
    FROM titles t, sales s
    WHERE t.title_id = s.title_id
    AND s.ord_date = (SELECT MAX(sales.ord_date) FROM sales)

Verwijderd

Op woensdag 17 juli 2002 14:38 schreef Debbus het volgende:
Volgens mijn handleiding moet INNER JOIN pas na de FROM en niet na de UPDATE...

[edit]:
code:
1
2
3
4
5
UPDATE titles
    SET ytd_sales = t.ytd_sales + s.qty
    FROM titles t, sales s
    WHERE t.title_id = s.title_id
    AND s.ord_date = (SELECT MAX(sales.ord_date) FROM sales)
Dat is een crossjoin ;)

Maar wel de juiste weg idd.

  • robjanssen
  • Registratie: September 2001
  • Laatst online: 02-08 16:10

robjanssen

Software Developer

Na de UPDATE regel krijg je toch eerst een SET regel?

Verwijderd

Op woensdag 17 juli 2002 19:40 schreef robjanssen het volgende:
Na de UPDATE regel krijg je toch eerst een SET regel?
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
UPDATE
Changes existing data in a table.

Syntax
UPDATE 
      { 
       table_name WITH ( < table_hint_limited > [ ...n ] ) 
       | view_name 
       | rowset_function_limited 
      } 
      SET 
      { column_name = { expression | DEFAULT | NULL } 
      | @variable = expression 
      | @variable = column = expression } [ ,...n ] 

    { { [ FROM { < table_source > } [ ,...n ] ] 

      [ WHERE 
        < search_condition > ] } 
      | 
      [ WHERE CURRENT OF 
      { { [ GLOBAL ] cursor_name } | cursor_variable_name } 
      ] } 
      [ OPTION ( < query_hint > [ ,...n ] ) ] 

< table_source > ::= 
    table_name [ [ AS ] table_alias ] [ WITH ( < table_hint > [ ,...n ] ) ] 
    | view_name [ [ AS ] table_alias ] 
    | rowset_function [ [ AS ] table_alias ] 
    | derived_table [ AS ] table_alias [ ( column_alias [ ,...n ] ) ] 
    | < joined_table > 

< joined_table > ::= 
    < table_source > < join_type > < table_source > ON < search_condition > 
    | < table_source > CROSS JOIN < table_source > 
    | < joined_table > 

< join_type > ::= 
    [ INNER | { { LEFT | RIGHT | FULL } [ OUTER ] } ] 
    [ < join_hint > ] 
    JOIN 

< table_hint_limited > ::= 
    {    FASTFIRSTROW 
      | HOLDLOCK 
      | PAGLOCK 
      | READCOMMITTED 
      | REPEATABLEREAD 
      | ROWLOCK 
      | SERIALIZABLE 
      | TABLOCK 
      | TABLOCKX 
      | UPDLOCK 
    } 

< table_hint > ::= 
    {    INDEX ( index_val [ ,...n ] ) 
      | FASTFIRSTROW 
      | HOLDLOCK 
      | NOLOCK 
      | PAGLOCK 
      | READCOMMITTED 
      | READPAST 
      | READUNCOMMITTED 
      | REPEATABLEREAD 
      | ROWLOCK 
      | SERIALIZABLE 
      | TABLOCK 
      | TABLOCKX 
      | UPDLOCK 
    } 

< query_hint > ::= 
    {    { HASH | ORDER } GROUP 
      | { CONCAT | HASH | MERGE } UNION 
      | {LOOP | MERGE | HASH } JOIN 
      | FAST number_rows 
      | FORCE ORDER 
      | MAXDOP 
      | ROBUST PLAN 
      | KEEP PLAN 
    }

zo. :)