Visualizzazione dei risultati da 1 a 7 su 7

Discussione: Query Sql Server 2000

  1. #1
    Utente di HTML.it
    Registrato dal
    Feb 2002
    Messaggi
    112

    Query Sql Server 2000

    Salve ragazzi,
    devo effettuare una query su un db che mi somma i dati di un campo, data una certa condizione, e li riporta le somme divise per codice prodotto su un'altro db.
    questa è la query

    codice:
    SELECT dbo.Vp.[Sap Product code], dbo.Vp.[Sale date], dbo.Vp.[Sale quantity UMB] 
    
    SUM dbo.Vp.Sale quantity UMB FROM dbo.Vp INNER JOIN dbo.somma ON Vp.Sap Product code=somma.Sap Product code 
    WHERE ([Sap Product code] = '16662') OR ([Sap Product code] = '16661') OR ([Sap Product code] = '16663') OR ([Sap Product code] = '16664') OR ([Sap Product code] = '17189') OR ([Sap Product code] = '17190') OR ([Sap Product code] = '17191') OR ([Sap Product code] = '17192') OR ([Sap Product code] = '17802') OR ([Sap Product code] = '17803') OR ([Sap Product code] = '17804') OR ([Sap Product code] = '17805') 
    GROUP BY [Sap Product code], [Sale date], [Sale quantity UMB] 
    HAVING ([Sale date] LIKE '= 102009%') 
    ORDER BY [Sale date]
    mi va in errore in continuazione.
    Avete qualche suggerimento?

    grazie

  2. #2
    Utente di HTML.it L'avatar di comas17
    Registrato dal
    Apr 2002
    Messaggi
    6,523
    "Mi va in errore" è un po' generico...
    Che errore ti dà ?

    Manca una virgola prima di SUM e, per semplicità di lettura e modifica, io metterei intanto

    ... WHERE [Sap Product Code] IN ('16662','16661','16663'....)

  3. #3
    Utente di HTML.it
    Registrato dal
    Feb 2002
    Messaggi
    112
    ho rifatto la query:
    codice:
    SELECT dbo.Vp.[Sap Product code], dbo.Vp.[Sale date], dbo.Vp.[Sale quantity UMB], 
    SUM dbo.Vp.[Sale quantity UMB] FROM dbo.Vp INNER JOIN dbo.somma ON Vp.Sap Product code=somma.Sap Product code 
    WHERE [Sap Product code] IN ('16662','16661','16663','16664','17189','17190','17191','17192','17802','17803','17804','17805') GROUP BY [Sap Product code], [Sale date], [Sale quantity UMB] 
    HAVING ([Sale date] LIKE '= 102009%') ORDER BY [Sale date]
    l'errore è

    codice:
    Server: Msg 170, Level 15, State 1, Line 1 Line 1: Incorrect syntax near '.'.

  4. #4
    Utente di HTML.it L'avatar di comas17
    Registrato dal
    Apr 2002
    Messaggi
    6,523
    nella seconda riga metterei le parentesi quadrate su [Sap Product Code]

    ...INNER JOIN dbo.somma ON Vp.[Sap Product code]=somma.[Sap Product code]...

  5. #5
    Utente di HTML.it
    Registrato dal
    Feb 2002
    Messaggi
    112
    Originariamente inviato da comas17
    nella seconda riga metterei le parentesi quadrate su [Sap Product Code]

    ...INNER JOIN dbo.somma ON Vp.[Sap Product code]=somma.[Sap Product code]...
    infatti, grazie!!

    ora la query:
    codice:
    SELECT Vp.[Sap Product code], Vp.[Sale date], Vp.[Sale quantity UMB], SUM (Vp.[Sale quantity UMB]) FROM Vp INNER JOIN somma ON Vp.[Sap Product code]=somma.[Sap Product code] WHERE [Sap Product code] IN ('16662','16661','16663','16664','17189','17190','17191','17192','17802','17803','17804','17805') GROUP BY [Sap Product code], [Sale date], [Sale quantity UMB] HAVING ([Sale date] LIKE '= 102009%') ORDER BY [Sale date]
    ma l'errore
    codice:
    Server: Msg 209, Level 16, State 1, Line 1 Ambiguous column name 'Sap product code'. Server: Msg 209, Level 16, State 1, Line 1 Ambiguous column name 'Sap product code'. Server: Msg 209, Level 16, State 1, Line 1 Ambiguous column name 'Sap product code'. Server: Msg 209, Level 16, State 1, Line 1 Ambiguous column name 'Sap product code'.

  6. #6
    Utente di HTML.it L'avatar di comas17
    Registrato dal
    Apr 2002
    Messaggi
    6,523
    dopo il WHERE devi indicare anche la tabella a cui questo [Sap Product Code] appartiene
    (hai lo stesso nome colonna in due tabelle, Vp e Somma e non sa quale intendi, quindi metterai
    WHERE Vp.[Sap Product Code].....
    oppure
    WHERE somma.[Sap Product Code].....

  7. #7
    Utente di HTML.it
    Registrato dal
    Feb 2002
    Messaggi
    112
    Originariamente inviato da comas17
    dopo il WHERE devi indicare anche la tabella a cui questo [Sap Product Code] appartiene
    (hai lo stesso nome colonna in due tabelle, Vp e Somma e non sa quale intendi, quindi metterai
    WHERE Vp.[Sap Product Code].....
    oppure
    WHERE somma.[Sap Product Code].....
    si infatti,
    grazie

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.