Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Specifing a column in the where clause
Message
 
 
À
19/02/2004 18:43:11
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00879002
Message ID:
00879005
Vues:
18
Darren,

SQL Server doesn't accept column aliases in WHERE, HAVING or GROUP BY clause. You either have to use column expression again or use derived table as shown bellow.
SELECT * 
	FROM (select customer_id,customer_nme, 
		(select sum(sell_amount) from sales 
		where sales.customer_id=customer.customer_id) as sales_total
		from customer) dt
where sales_total>0
order by 3,2 desc
Using derived table most likely will produce the same execution plan as using expression and shouldn't affect query performance.


>In this example:
>
>select customer_id,customer_nme,(select sum(sell_amount) from sales where sales.customer_id=customer.customer_id) as sales_total
>from customer
>where sales_total>0
>order by 3,2 desc
>
>Why do I get the error message: Invalid column name 'sales_total'?
>Is there a way around this without having to repeat the query in the where command (similar to the order command where you just specify the column number)?
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform