Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL - Server Syntax
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00509329
Message ID:
00509358
Vues:
13
Hi!

storedetails.name fields have no menaing in VFP too, they can return incorrect values. This is because how you determine which record should be used to return these values from the set of records used by sum()? You require to group also by a name field:

select sum(sales.qty),sum(sales.dollarvalue),storedetails.name,sales.store
from sales,storedetails
where sales.store = storedetails.store
group by sales.store, storedetails.name

In addition, if there are more than one record in storedetails for sales, you will get incorrcet sum because record repeating from stores table. Select sum first, than get the names in such case:
select a.*, storedetails.name
  from (
    select sum(sales.qty),sum(sales.dollarvalue),sales.store
      from sales
      group by sales.store
    ) a,storedetails
  where sales.store = storedetails.store

HTH.
>Hi guys,
>
>I have 2 tables in sql server.
>
>Sales,Storedetails
>
>** In VFp I would write
>select sum(sales.qty),sum(sales.dollarvalue),storedetails.name,sales.store;
>from sales,storedetails;
>where sales.store = storedetails.store;
>group by sales.store
>
>If I try the same syntax in SQL-Server I get an error..
>Storedetails is not involved in an aggregate.. How do I get around this problem in SQL - Server..
Vlad Grynchyshyn, Project Manager, MCP
vgryn@yahoo.com
ICQ #10709245
The professional level of programmer could be determined by level of stupidity of his/her bugs

It is not appropriate to say that question is "foolish". There could be only foolish answers. Everybody passed period of time when knows nothing about something.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform