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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Indexed view help (immediate)

Author  Topic 

egemen_ates
Yak Posting Veteran

76 Posts

Posted - 2012-06-18 : 05:18:05
i want to create index on view but im using derivate table please i need to optimize my query.my query show belown.

SELECT
ROUND(SUM(REAL_STOCK),4) REAL_STOCK,
ROUND(SUM(PRODUCT_STOCK),4) PRODUCT_STOCK,
ROUND(SUM(PRODUCT_STOCK+RESERVED_STOCK),4) SALEABLE_STOCK,
ROUND(SUM(PURCHASE_ORDER_STOCK),4) PURCHASE_ORDER_STOCK,
PRODUCT_ID,
STOCK_ID FROM (

SELECT
(SR.STOCK_IN - SR.STOCK_OUT) AS REAL_STOCK,
0 AS PRODUCT_STOCK,
0 AS RESERVED_STOCK,
0 AS PURCHASE_ORDER_STOCK,
SR.STOCK_ID,
SR.PRODUCT_ID
FROM
DBO.STOCK_123 SR
UNION ALL
SELECT
0 AS REAL_STOCK,
(SR.STOCK_IN - SR.STOCK_OUT) AS PRODUCT_STOCK,
0 AS RESERVED_STOCK,
0 AS PURCHASE_ORDER_STOCK,
SR.STOCK_ID,
SR.PRODUCT_ID
FROM
dbo.STOCK_123_DENEME SL,
DBO.STOCK_123 SR
WHERE
SR.STORE =SL.DEPARTMENT_ID
AND SR.STORE_LOCATION=SL.LOCATION_ID
AND SL.NO_SALE = 0)AS T

GROUP BY
PRODUCT_ID,
STOCK_ID

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-06-18 : 05:47:24
Have a look at indexed views - creating in bol.
Particularly the sql keywords that are not allowed in an indexed view query statement.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-06-18 : 12:23:33
without showing some data and explaining what you're trying to do its hard for someone to suggest on what to be done for optmising. would you post some sample data with required output for us?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -