Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How do I use the alias names in my view

Author  Topic 

hallyvaux
Starting Member

12 Posts

Posted - 2011-05-02 : 17:18:51
I created a view from my last report and I need to use the alias names for various reports and I cannot for the life of me remember how to do this. For instance, I created a view based on this report

SELECT NAME "Proudct Name", SUM(ORDERQTY)"Qty Ordered" ,SUM(SELLPRICE) "Price Sold" ,SUM(SELLPRICE) * SUM(ORDERQTY) "Total Sale"
FROM GS_SALES,GS_PRODUCTS
WHERE GS_SALES.PRODID = GS_PRODUCTS.PRODID
GROUP BY SELLPRICE, NAME
ORDER BY SELLPRICE DESC;


The view I created is

Create view problem7View AS
SELECT NAME "Proudct Name", SUM(ORDERQTY)"Qty Ordered" ,SUM(SELLPRICE) "Price Sold" ,SUM(SELLPRICE) * SUM(ORDERQTY) "Total Sale"
FROM GS_SALES,GS_PRODUCTS
WHERE GS_SALES.PRODID = GS_PRODUCTS.PRODID
GROUP BY SELLPRICE, NAME
ORDER BY SELLPRICE DESC;


Now when I go to select column names to use them (Select "Qty Ordered" From problem7View), it says that it doesn't exist. I'm sorry that this is super basic but I'm very new to this.

Thank you.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-05-02 : 17:38:07
SELECT NAME AS [Product Name]...

Tip: Do not use put spaces in names. Instead use underscores or camel case: SELECT Name AS ProductName.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

hallyvaux
Starting Member

12 Posts

Posted - 2011-05-02 : 17:39:29
Ok. That makes sense. I was just creating the view off of the report where I wanted the spaces but to create the view I went back and changed to names like qty_ordered. Ty. :)
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-05-02 : 17:40:19
You're welcome, glad to help.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -