|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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?
|
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > Transact-SQL - Select query returns far more results when put in stored procedure (urgent please) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|