SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old May 25th, 2009, 08:12 PM
naturehermit naturehermit is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2009
Posts: 2 naturehermit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 54 m 12 sec
Reputation Power: 0
Transact-SQL - Select query returns far more results when put in stored procedure (urgent please)

I have a select query like this

SELECT master_feed_product.id as MasterFeedProductId
,ISNULL(MasterTaxonomy.Id , -1) AS MasterCategoryId
,ISNULL(MasterTaxonomy.CategoryName, 'Unmapped') AS MasterCategory
,[mf_product_title] AS ProductTitle
,[mf_product_sku] AS ProductSku
,SUM(partner_click.p_click_cost) AS TotalCost
,SUM(ISNULL(product_checkout.total, 0)) AS SalesRevenue
,COUNT(product_checkout.itemcount) AS OrderCount
,[TopProduct] AS TopProduct
,[price_col_value] AS Price

,master_feed_product.[created]AS CreatedDate



FROM [onefeed].[dbo].[master_feed_product]

LEFT OUTER JOIN MasterTaxonomy
ON MasterTaxonomy.Id = master_feed_product.TaxonomyId

INNER JOIN feeds
ON feeds.id = master_feed_product.feed_id

INNER JOIN brands
ON brands.id = feeds.brand_id
AND
(@localMerchantId IS NULL OR brands.merchant_id = @localMerchantId) AND
(@localBrandId IS NULL OR brands.id = @localBrandId)
full outer join partner_click
On master_feed_product.id = partner_click.product_id



full outer join product_checkout
On partner_click.merchant_id = product_checkout.merchant_id AND
partner_click.product_id = product_checkout.product_id AND
partner_click.click_id = product_checkout.click_id

where

(@localActive IS NULL OR master_feed_product.Active = @localActive)

and
(ISNULL(@localMasterCategory, '') = '' OR MasterTaxonomy.CategoryName like @localMasterCategory)

And
(@localDateFrom IS NULL OR master_feed_product.created >= @localDateFrom) AND
(@localDateTo IS NULL OR master_feed_product.created <= @localDateTo) --AND
--partner_click.is_bot = 0
AND
ISNULL(product_checkout.duplicate, 0) = 0


GROUP BY master_feed_product.id,
MasterTaxonomy.Id,
MasterTaxonomy.CategoryName,
master_feed_product.mf_product_title,
master_feed_product.mf_product_sku,
master_feed_product.TopProduct,
master_feed_product.price_col_value,
master_feed_product.created



ORDER BY master_feed_product.id



But when i put this is a stored procedure, I get far more results than it is ...

How can i modify my sp to have corect values

Reply With Quote
  #2  
Old June 20th, 2009, 12:30 AM
June7 June7 is offline
Contributing User
Click here for more information.
 
Join Date: Apr 2009
Location: The Great Land
Posts: 1,116 June7 User rank is Captain (20000 - 30000 Reputation Level)June7 User rank is Captain (20000 - 30000 Reputation Level)June7 User rank is Captain (20000 - 30000 Reputation Level)June7 User rank is Captain (20000 - 30000 Reputation Level)June7 User rank is Captain (20000 - 30000 Reputation Level)June7 User rank is Captain (20000 - 30000 Reputation Level)June7 User rank is Captain (20000 - 30000 Reputation Level)June7 User rank is Captain (20000 - 30000 Reputation Level)June7 User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Weeks 23 h 41 m 25 sec
Reputation Power: 240
This is the longest and most complicated SELECT query I've seen. Think you might have too many groups in the GROUP BY clause. Suggest you start with a simpler query and then build up. Try just one aggregate function and one group then if results make sense add another aggregate function. At some point the combination will bring a failure, as you have now. You might find it necessary to do multiple queries. What database app are you using?

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > Transact-SQL - Select query returns far more results when put in stored procedure (urgent please)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump





 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek