SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Indexed view help (immediate)
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

egemen_ates
Yak Posting Veteran

Turkey
63 Posts

Posted - 06/18/2012 :  05:18:05  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

United Kingdom
3328 Posts

Posted - 06/18/2012 :  05:47:24  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
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

India
47023 Posts

Posted - 06/18/2012 :  12:23:33  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000