15,891,793 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by ChandrakanthGaddam (Top 1 by date)
ChandrakanthGaddam
7-Jan-13 5:12am
View
Hi
Thanks for responding my questions. I have executed entire query by passing parameters. Please find the Query below.
---------------------------------------------------------
declare @DateVal Varchar(250) = '07/10/2012',
@PnlSelValue varchar(50) = 'Weekly',
@YearNumber int = 2012,
@Category varchar(max)= '0'
Declare @TTotalProductsValue int
Declare @LTotalProductsValue int
declare @WeekNo int,@MonthNo int
declare @SubCategoryCommasep varchar(max)
declare @count int
select distinct @count=count(Category) from iView_ProductMaster
where Category in ((Select convert(varchar,ID) From fnSplitter(@Category)))
if @count > 0
begin
select @SubCategoryCommasep = COALESCE(@SubCategoryCommasep + ',', '') + Cast(SubCategory as varchar(1000)) from iView_ProductMaster
where Category in ((Select convert(varchar,ID) From fnSplitter(@Category)))
print @SubCategoryCommasep
end
else
begin
set @SubCategoryCommasep = 0
end
IF @PnlSelValue = 'Weekly' or @PnlSelValue = 'Bi-Weekly'
begin
set @DateVal = CONVERT(datetime,@DateVal,103)
select @WeekNo = convert(varchar(10),datepart(wk,@DateVal)), @MonthNo = convert(varchar(10),Month(@DateVal)) ,@YearNumber = convert(varchar(10),year(@DateVal))
end
else if @PnlSelValue = 'Monthly' or @PnlSelValue='Yearly'
begin
set @DateVal = @DateVal
set @YearNumber = @YearNumber
end
SELECT @TTotalProductsValue = SUM(TotalSales), @LTotalProductsValue = SUM(TotalSalesLY) FROM dbo.tbl_Aggregated_Data
Where WeekDate = @DateVal and Yearnumber = @YearNumber and PeriodType = @PnlSelValue
and EAN in (Select EAN from iView_ProductMaster where Category = @Category);
with t as
(select dbo.[InitCap](p.Category)as Category,Sum(d.TotalSalesLY) as 'TotalSalesLY',
Sum(d.TotalSales) as 'TotalSales',Sum(d.TotalUnitsLY) as TotalUnitsLY,Sum(d.TotalUnits) as TotalUnits,
Sum(StoreCountLY) as 'Storecount LY',Sum(StoreCountTY) as 'StoreCount TY'
from tbl_Aggregated_Data d inner join iView_ProductMaster p on p.EAN = d.EAN
Where d.PeriodType = @PnlSelValue and d.WeekDate = @DateVal and Yearnumber = @YearNumber
and d.EAN in (Select EAN from iView_ProductMaster where
(@count =0 or p.Category in (Select convert(varchar,ID) From fnSplitter(@SubCategoryCommasep))))
group by p.Category)
select Category,TotalSalesLY,TotalSales,TotalUnitsLY,TotalUnits,
Convert(decimal(18,1),dbo.ValueShare(TotalSalesLY,@LTotalProductsValue))as ValueShareLY,
Convert(decimal(18,1), dbo.ValueShare(TotalSales,@TTotalProductsValue))as ValueShareTY ,
Convert(decimal(18,1),dbo.ValueGrowth_Per_YA(TotalSalesLY,TotalSales)) as ValueGrowth,
[Storecount LY],[Storecount TY] from t;
Thanks
Chandrakanth