Showing posts with label sales. Show all posts
Showing posts with label sales. Show all posts

Thursday, March 29, 2012

Easy!! Subquery needs to show all Sales Reps, even when null

I have a subquery that grabs all the sales reps with less then 6 visits. Only problem is, when i have a date when there are any number of sales reps that dont make visits, so the column would be null, they dont show up. I want to display these, because this report is supposed to show the visits made, so if they made none, i want it to show zero, instead of not showing the whole date column, since zero visits were made on that date that were below 6 and more then zero. Here's my stored procedure: (the subquery is highlighted)

Code Snippet

ALTER PROCEDURE [dbo].[Testing_Visits_6]

(@.Region_Key int=null)

AS

BEGIN

SELECT dbo.Qry_Visits.Status,

dbo.Qry_Visits.Customer_code,

Qry_Sales_Group.Name,

dbo.Qry_Sales_Group.SR_Name,

dbo.Qry_Date_Dim.Date_Dimension_Fiscal_Week,

dbo.Qry_Date_Dim.Date_Dimension_Date,

dbo.Qry_Date_Dim.Day_Of_Month,

dbo.Qry_Sales_Group.Region,

dbo.Qry_Visits.period_code,

dbo.Qry_Visits.cycle_day, dbo.Qry_Visits.Visits,

dbo.Qry_Visits.time_log, dbo.Qry_Visits.Mailing_Name,

dbo.Qry_Date_Dim.Date_Dimension_Year,

dbo.Qry_Date_Dim.Date_Dimension_Period,

CONVERT(varchar, dbo.Qry_Visits.time_log, 110) AS Date,

dbo.Qry_Sales_Group.Region_Key, dbo.Qry_Visits.[SR Code],

B.VisitsTotal

FROM dbo.Qry_Visits

INNER JOIN dbo.Qry_Sales_Group

ON dbo.Qry_Visits.[SR Code]

COLLATE SQL_Latin1_General_CP1_CI_AS = dbo.Qry_Sales_Group.SalesPerson_Purchaser_Code

AND dbo.Qry_Visits.[SR Code] = dbo.Qry_Sales_Group.SalesPerson_Purchaser_Code

COLLATE Latin1_General_CI_AS

INNER JOIN dbo.Qry_Date_Dim

ON CONVERT(varchar, dbo.Qry_Date_Dim.Date_Dimension_Date, 110) = CONVERT(varchar, dbo.Qry_Visits.time_log, 110)

INNER JOIN ( Select COUNT(Visits)as VisitsTotal,[Sales Responsible],CONVERT(VARCHAR,(Qry_Visits.time_log),110)TheDate,Qry_Visits.Status

FROM dbo.Qry_Visits

WHERE Qry_Visits.Status=2

GROUP by [Sales Responsible] , CONVERT(VARCHAR,(Qry_Visits.time_log),110),Qry_Visits.Status

HAVING SUM(Visits) < 6)B

ON dbo.Qry_Sales_Group.SR_Name COLLATE Latin1_General_CI_AS = B.[Sales Responsible] COLLATE Latin1_General_CI_AS AND

CONVERT(varchar, dbo.Qry_Date_Dim.Date_Dimension_Date, 110) = B.TheDate

WHERE REGION_KEY=@.Region_Key and Qry_Visits.Status=2

ORDER BY dbo.Qry_Sales_Group.SR_Name, CONVERT(varchar, dbo.Qry_Date_Dim.Date_Dimension_Date, 110)

You'll need to do an outer join to your date dimension

|||

is there a way i can just say, if SUM(visits) is null then 0

or something like that?

|||

either this...

coalesce(sum(visits),0)

or this...

case

when sum(visits) is null then 0

else sum(visits)

end as 'SumVisits'

|||I guess technically this doesnt work because it doesnt change anything. I guess i just need to find a way to Display all dates that have visits, since all dates show up on my other report that displays all visits, no matter how many. Would i do another subquery to grab all dates where Visit is greater then zero?|||

Replace "INNER JOIN" with "LEFT OUTER JOIN", try the following...

ALTER PROCEDURE [dbo].[Testing_Visits_6]

(@.Region_Key int=null)

AS

BEGIN

SELECT dbo.Qry_Visits.Status,

dbo.Qry_Visits.Customer_code,

Qry_Sales_Group.Name,

dbo.Qry_Sales_Group.SR_Name,

dbo.Qry_Date_Dim.Date_Dimension_Fiscal_Week,

dbo.Qry_Date_Dim.Date_Dimension_Date,

dbo.Qry_Date_Dim.Day_Of_Month,

dbo.Qry_Sales_Group.Region,

dbo.Qry_Visits.period_code,

dbo.Qry_Visits.cycle_day, dbo.Qry_Visits.Visits,

dbo.Qry_Visits.time_log, dbo.Qry_Visits.Mailing_Name,

dbo.Qry_Date_Dim.Date_Dimension_Year,

dbo.Qry_Date_Dim.Date_Dimension_Period,

CONVERT(varchar, dbo.Qry_Visits.time_log, 110) AS Date,

dbo.Qry_Sales_Group.Region_Key, dbo.Qry_Visits.[SR Code],

IsNull(B.VisitsTotal,0) VisitsTotal

FROM dbo.Qry_Visits

INNER JOIN dbo.Qry_Sales_Group

ON dbo.Qry_Visits.[SR Code]

COLLATE SQL_Latin1_General_CP1_CI_AS = dbo.Qry_Sales_Group.SalesPerson_Purchaser_Code

AND dbo.Qry_Visits.[SR Code] = dbo.Qry_Sales_Group.SalesPerson_Purchaser_Code

COLLATE Latin1_General_CI_AS

INNER JOIN dbo.Qry_Date_Dim

ON CONVERT(varchar, dbo.Qry_Date_Dim.Date_Dimension_Date, 110) = CONVERT(varchar, dbo.Qry_Visits.time_log, 110)

LEFT OUTER JOIN (

Select COUNT(Visits)as VisitsTotal

, [Sales Responsible]

, CONVERT( VARCHAR,(Qry_Visits.time_log),110) as TheDate

, Qry_Visits.Status

FROM dbo.Qry_Visits

WHERE Qry_Visits.Status=2

GROUP by [Sales Responsible] , CONVERT(VARCHAR,(Qry_Visits.time_log),110),Qry_Visits.Status

HAVING SUM(Visits) < 6

)B

ON dbo.Qry_Sales_Group.SR_Name COLLATE Latin1_General_CI_AS = B.[Sales Responsible] COLLATE Latin1_General_CI_AS AND

CONVERT(varchar, dbo.Qry_Date_Dim.Date_Dimension_Date, 110) = B.TheDate

WHERE REGION_KEY=@.Region_Key and Qry_Visits.Status=2

ORDER BY dbo.Qry_Sales_Group.SR_Name, CONVERT(varchar, dbo.Qry_Date_Dim.Date_Dimension_Date, 110)

END

sql

Monday, March 26, 2012

Easy Questions - get me started

I have 3 retail sites running MSDE and I want to aggregate sales data at a
separate SQL Server. I run a VPN and I guess I need to use merge replication
to a full SQL Server Database. My questions are
1. Is the central server the publisher or subscriber
2. The three sites tables are identical and I would like a siteID added at
the table in the central server to distinguish which the data came from
3. If the central server is the publisher will unwanted data from one site
flow across to another.
4. Is what I am asking clear enough and is merge replication appropriate
For merge, the central SQL Server should be the publisher. If you filter
your articles by site name data will not flow to the other subscribers. For
your version of sql server, yes merge is the most appropriate.
However, does data only flow centrally? If so, transactional replication
would be faster, not require a guid column on each table (assuming you have
pks on each table). This would require at least sql server standard edition
everywhere.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Steve Hall" <SteveHall@.discussions.microsoft.com> wrote in message
news:A3AF25D9-8D4B-4C0E-80B6-E95ED675E82E@.microsoft.com...
>I have 3 retail sites running MSDE and I want to aggregate sales data at a
> separate SQL Server. I run a VPN and I guess I need to use merge
> replication
> to a full SQL Server Database. My questions are
> 1. Is the central server the publisher or subscriber
> 2. The three sites tables are identical and I would like a siteID added
> at
> the table in the central server to distinguish which the data came from
> 3. If the central server is the publisher will unwanted data from one site
> flow across to another.
> 4. Is what I am asking clear enough and is merge replication appropriate
|||Steve pls look at this:
http://www.replicationanswers.com/CentralSubscriberArticle.asp
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com
|||You guys rock!
That is two great replies within 30 minutes of posting.
Steve
"Paul Ibison" wrote:

> Steve pls look at this:
> http://www.replicationanswers.com/CentralSubscriberArticle.asp
> Cheers,
> Paul Ibison SQL Server MVP, www.replicationanswers.com
>
>

Sunday, March 11, 2012

Dynamically display/hide the parameter input

I have a handful of reports that are currently used by sales reps, and I'm trying to make them available to their regional VP's, and coporate users (executives and administrative staff that support Sales nationwide).

Currently, the reports take the UserID and resolve it to show the information that is only appropriate for that specific rep.

What I would like to do is have the parameter section at the top of the report be displayed for higher level users, so they could select an individual sales rep from a drop-down. (Ideally, the RVP's would only be able to select from reps in their region, but the corporate users would be able to select any rep.) The problem is, I don't want any of the sales reps to be able to select a rep other than themselves, for obvious reasons.

Is there a way to have the parameter section hidden/displayed dynamically, based on the UserID, so that users other than reps would have the ability to enter the desired rep name, but reps would not?

If you are using the .NET ReportView, it is just:

ReportViewer1.ShowParameterPrompts = False

|||I am using Report Manager.|||If you want any level of control, you are going to have to host the ReportViewer control in an ASP.NET page and customize the web page/report based on the user. There is not much you can do in ReportManager as far as fine control.|||

1. One way is to control this by writting a html page instead of report manager home page within which you will have a link to each of the report. Depending on who the user is you will change the path of the link (with or without parameters), meaning you will default all the parameters and pass them within the hidden link, but this wont work if you have more that 1 parameter and would want to hide only the user id parameter

2. Another option is to control this within the report. As your userid parameter list is being populated by a stored procedure, you will make the stored procedure accept a input parameter which is the userId of the person that is trying to run the report. Depending on who the user is the SP will return only the required users list.

Meaning

1. if XXX is passed and if XXX is RVP then it will return only the sales persons of XXX's region.

2. If YYY is passed and if YYY is sales person then it will return back only YYY

3. If CORP is passed and if CORP is a corporate user then the procedure will return all sales person's names

Hope this is clear and helps!!!

|||I think another way of achieving this is writting specific RDL code.|||

Thanks.

In the short term, this was the best solution. I wrote a sp that populates the drop down based on the NetLogin value.

So, the sales reps can see the drop down, but it only has their name in it.

|||You can also set the parameters visible in the URL using the &rsStick out tonguearameters=True/False.

i.e.

Code Snippet

http://SERVER/ReportServer/ReportPath&rs:Command=Render&rs:Parameters=False

HTH,
Jimmy

Friday, March 9, 2012

Dynamically Changing Images

Hi All:
I have a report that will be shared by a number of sales agents across a
number of different communities. The agents select a set of parameters and
run their report. Currently Community is one of the parameters they can
select.
I'd like to know if there is any way to dynamically change a graphic based
upon what Community is selected. We'd like to have only one report where the
logo can change rather than 12 different reports.
Thanks
BrennanWe have a property report that shows an image dynamically, our properties
have an ID number assigned to them.
ID number is one of the parameters of the report. On our webserver, we have
an image file (named the id number).
For example the user can choose building number 00818, and on the web server
is a corresponding image 00818.jpg.
We set the image type to external, and the value is an expression -
http://<yourserver>/BuildingImages/ & Parameters!ID.value & ".jpg"
This returns an image on the report based on the building the user has
chosen.
Chris
"Brennan" <Brennan@.discussions.microsoft.com> wrote in message
news:A3E076C0-EF3A-4903-B565-0DFA39A5A13A@.microsoft.com...
> Hi All:
> I have a report that will be shared by a number of sales agents across a
> number of different communities. The agents select a set of parameters
> and
> run their report. Currently Community is one of the parameters they can
> select.
> I'd like to know if there is any way to dynamically change a graphic based
> upon what Community is selected. We'd like to have only one report where
> the
> logo can change rather than 12 different reports.
> Thanks
> Brennan|||"Chris" wrote:
> We have a property report that shows an image dynamically, our properties
> have an ID number assigned to them.
> ID number is one of the parameters of the report. On our webserver, we have
> an image file (named the id number).
> For example the user can choose building number 00818, and on the web server
> is a corresponding image 00818.jpg.
> We set the image type to external, and the value is an expression -
> http://<yourserver>/BuildingImages/ & Parameters!ID.value & ".jpg"
> This returns an image on the report based on the building the user has
> chosen.
> Chris
> "Brennan" <Brennan@.discussions.microsoft.com> wrote in message
> news:A3E076C0-EF3A-4903-B565-0DFA39A5A13A@.microsoft.com...
> > Hi All:
> >
> > I have a report that will be shared by a number of sales agents across a
> > number of different communities. The agents select a set of parameters
> > and
> > run their report. Currently Community is one of the parameters they can
> > select.
> >
> > I'd like to know if there is any way to dynamically change a graphic based
> > upon what Community is selected. We'd like to have only one report where
> > the
> > logo can change rather than 12 different reports.
> >
> > Thanks
> > Brennan
>
>
Thanks Chris|||You can also use a "switch" expression in your value field for the
image:
switch(parameters!community.value = 'x', image1,
parameters!community.value = 'y', image2, ...)
Brennan wrote:
> "Chris" wrote:
> > We have a property report that shows an image dynamically, our properties
> > have an ID number assigned to them.
> > ID number is one of the parameters of the report. On our webserver, we have
> > an image file (named the id number).
> > For example the user can choose building number 00818, and on the web server
> > is a corresponding image 00818.jpg.
> > We set the image type to external, and the value is an expression -
> > http://<yourserver>/BuildingImages/ & Parameters!ID.value & ".jpg"
> >
> > This returns an image on the report based on the building the user has
> > chosen.
> >
> > Chris
> >
> > "Brennan" <Brennan@.discussions.microsoft.com> wrote in message
> > news:A3E076C0-EF3A-4903-B565-0DFA39A5A13A@.microsoft.com...
> > > Hi All:
> > >
> > > I have a report that will be shared by a number of sales agents across a
> > > number of different communities. The agents select a set of parameters
> > > and
> > > run their report. Currently Community is one of the parameters they can
> > > select.
> > >
> > > I'd like to know if there is any way to dynamically change a graphic based
> > > upon what Community is selected. We'd like to have only one report where
> > > the
> > > logo can change rather than 12 different reports.
> > >
> > > Thanks
> > > Brennan
> >
> >
> >
>
> Thanks Chris

Friday, February 24, 2012

dynamic table columns

I have a sproc that returns sales amount for each month in a given range of
dates. The date range is over the last 8 years, and will grow automatically
as time goes by.
I really do not want to create a table in RS with over 120 columns of data
and then set each of them to display/hide based on the parameters passed.
Matrix table doesnt seem to work for me as I dont want to un-pivot my data
just so it can pivot it back out.
Is there some solution to this problem? I have 5 base columns that will show
regardless of what yeear/month is passed, and usually anywhere from 12 to 48
result columns. is there a way for the table to recognize how many columns
are in the result set and create enough columns automagically?
Thanks!!On Dec 6, 4:03 pm, Carl Henthorn
<CarlHenth...@.discussions.microsoft.com> wrote:
> I have a sproc that returns sales amount for each month in a given range of
> dates. The date range is over the last 8 years, and will grow automatically
> as time goes by.
> I really do not want to create a table in RS with over 120 columns of data
> and then set each of them to display/hide based on the parameters passed.
> Matrix table doesnt seem to work for me as I dont want to un-pivot my data
> just so it can pivot it back out.
> Is there some solution to this problem? I have 5 base columns that will show
> regardless of what yeear/month is passed, and usually anywhere from 12 to 48
> result columns. is there a way for the table to recognize how many columns
> are in the result set and create enough columns automagically?
> Thanks!!
I guess I'm failing to see why you have to return all of the data
unaggregated to RS. Why not just limit the amount of months by
passing the correct parameters to your stored procedure? Then you
could just let the Matrix do its job and dynamically create the
columns.
If you absolutely have to do it this way, go to the Matrix Properties,
Filter tab, and add some log here to determine which of the Months
(that Group) you want to see. This will have the same effect as
setting the Visible on the columns. It will not speed up the data
fetch portion of your report.
If you could provide a little more detail as to what you are actually
trying to do, it would be helpful. What kind of groupings do you have
in the rows, since Months are your columns? Are you manually creating
multiple Rows, each with a different field in your dataset? There are
many ways to get to the same outcome.
-- Scott