Grouping / Reporting Question
Oct 11, 2007
Hi,
I've written a series of procedures that are writing output lines into a common table that I'm then reporting on.
I've included some simplified code to show waht I've done.
I was hoping someone could tell me if it is possible to remove the loop that I've created to get the report headings.
I've tried to write this as a with statement, but can't quite get it right.
--------
CREATE TABLE JobReport(
JobRunId int NOT NULL,
ReportDate datetime NOT NULL,
Process] varchar(200) NOT NULL,
Line varchar(200) NOT NULL
)
INSERT INTO jobreport(jobrunid,reportdate,process,line)
SELECT 1,CURRENT_TIMESTAMP,'Proc A','testline A1' union
SELECT 1,CURRENT_TIMESTAMP,'Proc A','testline A2' union
SELECT 1,CURRENT_TIMESTAMP,'Proc A','testline A3' union
SELECT 1,CURRENT_TIMESTAMP,'Proc b','testline b1' union
SELECT 1,CURRENT_TIMESTAMP,'Proc b','testline b2' UNION
SELECT 1,CURRENT_TIMESTAMP,'Proc b','testline b3' UNION
SELECT 1,CURRENT_TIMESTAMP,'Proc c','testline c1' UNION
SELECT 1,CURRENT_TIMESTAMP,'Proc c','testline c2' UNION
SELECT 1,CURRENT_TIMESTAMP,'Proc c','testline c3' UNION
SELECT 1,CURRENT_TIMESTAMP,'Proc c','testline c4' UNION
SELECT 1,CURRENT_TIMESTAMP,'Proc d','testline d1' UNION
SELECT 1,CURRENT_TIMESTAMP,'Proc d','testline d2' UNION
SELECT 1,CURRENT_TIMESTAMP,'Proc d','testline d3'
SELECT IDENTITY(INT,1,1) id,headings.Process INTO #headings from
(
SELECT Process FROM jobreport
WHERE jobrunid = 1
GROUP BY Process
) headings
BEGIN
DECLARE @max INT, @COUNT INT,@heading AS VARCHAR(200),@report VARCHAR(MAX), @jobrunid INT
SET @jobrunid = 1
set @report = ''
SELECT @max = COUNT(*) FROM #headings
SET @count = 0
WHILE @count < @max
BEGIN
SET @count = @count + 1
SELECT @heading = h.Process FROM #headings h WHERE h.id = @count
SELECT @report = @report + '----' + @heading + '----' + CHAR(13)
SELECT @report = @report + line + CHAR(13)
FROM jobcontrol.dbo.jobreport rep
WHERE rep.jobrunid = @jobrunid
AND rep.Process = @heading
END
--------
any help would be appreciated.
thanks
Sean
View 4 Replies
ADVERTISEMENT
Feb 7, 2007
Can anyone help me with grouping in Reporting services. I am more used to crystal reports drill-down method
For example i have a simple table that has timestamp and three other columns. I want to drill down by (after Grouping) for Day-Then- Hour and then show the details for three columns. And also group by one of the columns, if i get above working.
All i could do with Reporting services was stepped down model, but i have same dates repeated more than once. i would like them to be grouped under day and then show time stamps for times of day .
-Thanks all
View 1 Replies
View Related
Apr 23, 2015
I have created a Table within SQL Server Report Builder, and the first field is a calculated field with the following code:
=Code.ChangeWord(Fields!NAME.Value)
Where the function is
Public Function ChangeWord(ByVal s As String) As String
Dim strBuilder As New System.Text.StringBuilder(s) If s.Contains("ESI ") Then
strBuilder.Replace(s,"ESI")
Return strBuilder.ToString()
Else : Return s End IfEnd Function
Now, when I execute this, it works beautifully ... except that the Grouping mechanism doesn't group all instances of "ESI" together, like I want it to.
How do I change this behavior so that it groups all instances of "ESI" together, like it should?
View 3 Replies
View Related
Dec 4, 2007
Hi,
I want to create a number of Groups in a table.
Within each group I want to display that group's data details.
So far I seem to be only able to create another SubGroup within a Group.
I want my data to display as follows(using Drilldown)...
ItemA
ItemA Details
ItemA DetailsExtra
ItemB
ItemB Details
ItemC
ItemC Details
ItemC DetailsExtra
thanks.
View 7 Replies
View Related
Aug 17, 2007
Hi there.
I am working on a set of reports where I am summing/averaging data elements based on what period they are in. For example, the report output should look something like this:
Period
Sum
May '07
41
April '07
14
Q2 '07
55
March '07
36
February '07
28
January '07
22
Q1 '07
86
June '07
N/A
YTD '07
141
December '06
33
November '06
27
October '06
42
Q4 '06
102
September '06
58
August '06
84
July '06
52
Q3 '06
194
June '06
40
May '06
41
April '06
14
Q2 '06
95
March '06
67
February '06
38
January '06
N/A
Q1 '06
105
YTD '06
496
For each of the items I am summing, all I have is a datetime of when the event happened. This is a relational database (not a cube), so I am struggling with how to create the 'buckets' based on period. I think the best way is to dynamically create the buckets based on a given date. Is there a way in RS that it can do this bucketing for you?
Thanks, Mike
View 4 Replies
View Related
Aug 11, 2015
I would like to create a group and add an overall header.
So the dimension is grouped and results in the following:
Group Title
Dimension 1 Dimension 1 Dimension 1 Dimension 1
Instead of :
Group Title Group Title Group Title Group Title
Dimension Dimension Dimension Dimension
How can I achieve this without using a tablix within a tablix?
View 6 Replies
View Related
Aug 31, 2015
I create a matrix,
Row groups: Province
Column groups: Project Type
Values: Count of # of Projects, Sum of Amount ($)
What this displays is the following. How do I go about calculating what's highlighted in yellow? It is Amount of OneProjectType / Amount of TwoProject Type.
View 5 Replies
View Related
Jun 15, 2015
I am creating a report that shows orders created by our employees but I am having trouble with one employee. She changed her last name this year and so in the report, it shows a line her with her maiden name and one with her new name.
Is there a way to combine all the data from both names into one name so it appears on one line and looks like a single person instead of two.
View 4 Replies
View Related
Jan 23, 2008
Have anyone came across an issue with Reporting Service 2005 where if you had more than 1 group within a table and the first group has the property 'Page Break at end' checked - this will cause a page break after the group footer was printed.
Usually this is not an issue but consider this scenario - the 'Page Break at end' is set against the second group (not the first group which show the overall total) - when the last footer was printed for the second group, this cause a page break before the first group (overall) is printed - it seem to me that Reporting Service is not able to know when not to generate a page break if there isn't any more data - more importantly - there dosen't appear to be a way to set an expression against 'Page Break at end' within the group
Does anyone know of this issue and is there a workaround it?
View 3 Replies
View Related
Jan 9, 2008
Is there a way in Reporting Services layout mode to get the report to display more than one response for one field in the same cell?
More specifically, I have a list of classes that lists section, title, and instructors. If the class has more than one instructor, I want the instructor cell to list both instructors in one cell, separated by a semi-colon, rather than listing all the class information - along with instructor - in two separate rows. Any suggestions?
something like this:
Section
Title
Instructors
15
Class 1
Jones
16
Class 2
Jones; Smith
View 5 Replies
View Related
Jul 6, 2015
I am working on one of the report. where I need to move the amount across column group.
My data is like this
Project Amount CurrentFiscalMonth DelaybyMonth
A 10 Jul 0
B 20 Aug 2
C 10 Sep 0
Report will be sum up the amount at CurrentFicalMonth grouping on column
But, if the Project is being delayed say by as per the example its 2 months than the amount should be moved from Sep to Oct column for the particular project. User has done it using the Offset function in excel.
Fiscal month starts at July and ends at June. and data source is SSAS cube.
View 4 Replies
View Related
Mar 5, 2014
Example: A sales report that details and summarizes each Salesperson’s total sales within a company’s stores that reside in each state.
The report has 3 levels of groupings where the highest 2 levels require summary counts on a separate page and the lowest level produces a summary count in the midst of the detail lines of the report.
The data consumed by the report is ordered by State, Store ID, and Salesperson.
The header of each page lists the State and Store ID. The detail lines of the report list items sold and the associated sales amount for each item sold by each store’s salesperson.
At the end of each Salesperson’s items sold, a summary line is listed on the next line in the report showing the total amount and total count of items sold by that Salesperson.
The very next line on the report lists items sold and the associated sales amount for the next Salesperson within that particular store.
Summary lines will be produced for each Salesperson within each particular store on the next line of detail in the report.
At the end of all sales data for each store, a summary page is produced on a separate page listing the summary of each Salesperson’s totals.
Each line of the summary page contains the same counts for each Salesperson that was embedded in the detail section of the report.
The summary page also contains a grand total line listing the total count and sales for all salesmen within each given store.
At the end of all sales data for each state a summary page is produced on a separate page listing the summary of each store’s totals.
Each line of the summary page contains the grand totals of all sales for each store within a given state.
The summary page also contains a grand total line listing the total count and sales for all stores within each given state.
The simple breakdown is the groupings and totals for each state and store must be listed on a separate page in the report.
The grouping and totals for each Salesperson must be listed on the next line within the detail section of the report.
Current issue: The requirement is for no page break at the end of each salesperson’s sales data because the page breaks produce too many extra pages in the report.
Disabling the page break at the Salesperson level produces format issues such as page headers printing on the next line in the report before each Salesperson’s summary line.
Disabling the page breaks at this level also produces the problem of suppressing the page break for the summary page that comes at the end of each store.
Question:The report has 3 levels of grouping with Salesperson at the lowest level, Store ID being the parent group of Salesperson, and State being the parent group of Store ID. Is it possible to format the Salesperson summary line (lowest level grouping) as just another detail line in the report without impacting the report format that requires page breaks at the parent group levels?
A sample report layout of what we are trying to achieve is on the next page.
Sales Report
State: Alaska
Store ID: 100
Item Sold
Sales Amount
Hammer
$10.00
Saw
$15.00
[Code] .....
View 2 Replies
View Related
Apr 28, 2015
I want to display data in following format in ssrs report.
Rank Group Value
1 G1 10
2 G1 20
3 G1 30
4 G1 40
1 G2 25
2 G2 54
3 G2 64
I tried row count and other ranking functions but it did not working.
View 3 Replies
View Related
Jun 23, 2015
I have table which has 5 columns(col1,col2,col3,col4,col5) very simple and some data .
I would like to create a tabular report datasets on the report like shown below with grouping on col1
like
col1 some static text and dynamic text
------------------------
col1 col2 col3 col4
data data data data
------------------------
col1 some static & dynamic text
------------------------
col1 col2 col3 col4
data data data data
------------------------
Note I need to keep all the tables on the same page and when exported in excel they should come on same page sheet.
View 2 Replies
View Related
Sep 23, 2015
I am trying to add a filter and sorting to a matrix, within the matrix I have a column which works out the percentage and is as follows
=(Sum(Fields!Sum_Distinct_JobBilledExVAT.Value) + Lookup(Fields!ClientId.Value, Fields!JobClientId.Value, Fields!Sum_JobBilledExVAT.Value, "ProfJobClientsFees") + Lookup(Fields!ClientId.Value, Fields!ClientId.Value, Fields!Sum_JobBilledExVAT.Value, "ProfClientsFeesID")) / (Lookup(Fields!ClientId.Value, Fields!ClientId.Value, Fields!Sum_MatchedToOtherPost.Value, "ProfClientsMatch") + Lookup(Fields!ClientId.Value, Fields!ClientId.Value, Fields!Sum_JobBilledExVAT.Value, "ProfClientsCC") + Lookup(Fields!ClientId.Value, Fields!ClientId.Value,
[Code] ....
I tried enclosing the query in Abs( ), which I have done in the past, although in the past I wasn't using Lookup functions so I don't know if that is the reason it won't work.
View 6 Replies
View Related
Jul 23, 2015
SSRS 2008 R2
I have two level of grouping Example:
:::HEADER:::
A [GROUPING 1]
B[GROUPING 2]
C[GROUPING 2]
When I apply Page Break
:::HEADER:::
A [GROUPING 1]
B[GROUPING 2]
:::HEADER:::
A [GROUPING 1]
C[GROUPING 2]
[URL]
View 3 Replies
View Related
Sep 1, 2015
I want to develop a ssrs report which is grouped by month?
View 4 Replies
View Related
Nov 16, 2015
We are facing problem in doing page break with column grouping. Our column group contains years e.g 2011, 2013 . We want to show a complete page for a year.
Suppose 2011 has 10 records(horizontal) and 2013 has 12 records(horizontal) in column. The output should be 10 records of 2011 in first page, 12 records of 2013 in second page.
We cannot change the report layout to make column to row and vice versa.
View 3 Replies
View Related
Mar 27, 2012
We have a report that was created in SSRS 2008 R2 that has 3 tables with different datasets that share a common ID that I want to use to group them.
If we run the report passing only a single value for the grouped parameter then the report works perfectly. What we need is for this report to allow multiple values to be selected for this parameter and for the report to run as if the user had selected each value one at a time and run the report with page breaks in between. Currently, when we pass multiple selected values for the grouping parameter the report displays all values for table 1, then all values for table 2, then all values for table three as below:
Table 1:
Detail rows for Group Param Value 1 ...
Detail rows for Group Param Value 2 ...
Detail rows for Group Param Value 3 ...
....
Table 3:
Detail rows for Group Param Value 1 ...
Detail rows for Group Param Value 2 ...
Detail rows for Group Param Value 3 ...
But we want it to render like this:
Table 1:
Detail rows for Group Param Value 1...
Table 2:
Detail rows for Group Param Value 1...
Table 3:
Detail rows for Group Param Value 1...
[code]....
The page breaks are needed so that when the report is exported to excel each individual report (by group param) will be on its own uniquely named tab.The report must export cleanly to excel and currently does for the single value passed.
View 5 Replies
View Related
Nov 26, 2007
I'm really stumped on this one. I'm a self taught SQL guy, so there is probobly something I'm overlooking.
I'm trying to get information like this in to a report:
WO#
-WO Line #
--(Details)
--Work Order Line Detail #1
--Work Order Line Detail #2
--Work Order Line Detail #3
--Work Order Line Detail #etc
--(Parts)
--Work Order Line Parts #1
--Work Order Line Parts #2
--Work Order Line Detail #etc
WO#
-WO Line #
--(Details)
--Work Order Line Detail #1
--Work Order Line Detail #2
--Work Order Line Detail #3
--Work Order Line Detail #etc
--(Parts)
--Work Order Line Parts #1
--Work Order Line Parts #2
--Work Order Line Parts #etc
I'm unable to get the grouping right on this. Since the line details and line parts both are children of the line #, how do you do "parallel groups"?
There are 4 tables:
Work Order Header
Work Order Line
Work Order Line Details
Work Order Line Requisitions
The Header has a unique PK.
The Line uses the Header and a Line # as foreign keys that together are unique.
The Detail and requisition tables use the header and line #'s in addition to their own line number foreign keys. My queries ends up looking like this:
WO WOL WOLR WOLD
226952 10000 10000 10000
226952 10000 10000 20000
226952 10000 10000 30000
226952 10000 10000 40000
226952 10000 20000 10000
226952 10000 20000 20000
226952 10000 20000 30000
226952 10000 20000 40000
399999 10000 NULL 10000
375654 10000 10000 NULL
etc
Hierarchy:
WO > WOL > WOLD
WO > WOL > WOLR
It probobly isn't best practice, but I'm kinda new so I need some guidance. I'd really appreciate any help! Here's my query:
SELECT [Work Order Header].No_ AS WO_No, [Work Order Line].[Line No_] AS WOL_No,
[Work Order Requisition].[Line No_] AS WOLR_No, [Work Order Line Detail].[Line No_] AS WOLD_No
FROM [Work Order Header] LEFT OUTER JOIN
[Work Order Line] ON [Work Order Header].No_ = [Work Order Line].[Work Order No_] LEFT OUTER JOIN
[Work Order Line Detail] ON [Work Order Line].[Work Order No_] = [Work Order Line Detail].[Work Order No_] AND
[Work Order Line].[Line No_] = [Work Order Line Detail].[Work Order Line No_] LEFT OUTER JOIN
[Work Order Requisition] ON [Work Order Line].[Work Order No_] = [Work Order Requisition].[Work Order No_] AND
[Work Order Line].[Line No_] = [Work Order Requisition].[Work Order Line No_]
View 1 Replies
View Related
Jun 10, 2015
I have a report where in I want to show each record on a separate page.
So, to achieve that I took a single cell from table control, expanded it and used all the controls in that single cell. This looks nice so far.
Now, I also have to show a sub grid on each record. So I took a table control and added on the same single cell and tried to add a parent group to the table row.
When I preview, it throws this error.
"The tablix has a detail member with inner members. Detail members can only contain static inner members."
What am I doing wrong? How can I achieve table grouping inside a table cell?
View 2 Replies
View Related
May 11, 2008
Hi there, i have an SQL query which select the number of products and display them per sub_cat_id e.g.
7 french dressers3 spanish dressers1 english dresser
However what i want to do is then group those under the the main category (cat_id)
All descriptions are held in tbl_cat and and main category and sub category can be found by the cat_cat colum, if there is an M in this colum it means it is a main category e.g. beds, tables, if there is the name of a M category then it is a sub cat e.g. double beds, single beds etc.
Can anybody help me with my grouping nightmare?
this is the code i have so far
SELECT COUNT(tbl_stock.Stock_ID) AS TOTALOFSTOCK, tbl_stock.sub_cat_id, tbl_cat.Cat_DescriptionFROM tbl_stock INNER JOIN tbl_cat ON tbl_stock.sub_cat_id = tbl_cat.Category_IDGROUP BY tbl_cat.Cat_Description, tbl_stock.sub_cat_id
View 1 Replies
View Related
Jun 13, 2008
I have a table which lists manufacturers' products. Users are allowed to vote for the most popular item belonging to the manufacturer. Moderators assign the products to manufacturers so on occassion they may accidently (or deliberately) get it wrong. For this reason, the table also acts as the ChangeLog so if choose, I could instantly decide whether all changes made by a specific user should be dismissed. Product | Manufacturer | NoOfVotes | ChangedBy | ChangedTime
============ ============== =========== =========== =============
XBOX 360 Microsoft 25* Dic 05/03/2008
XBOX 360 Sony 1 Tom 04/03/2008
Playstation Sony 100* Dic 03/03/2008
XBOX 360 Microsoft 25* Dic 02/03/2008
XBOX 360 Sony 1 Harry 01/03/2008
I'm using ID fields for Product, Manufacturer and ChangedBy which are obtained from different tables but have simplified the table to make it easier to read.
I need to retrieve each product in the table, the last Manufacturer assigned to it, with a total of the votes where the product-manufacturer match. The results should be: Product | Manufacturer | TotalVotes | LastChanged
============ ============== ============ =============
XBOX 360 Microsoft 50 05/03/2008
Playstation Sony 100 03/03/2008
Any help would be greatly appreciated.
Thanks, Pete.
View 3 Replies
View Related
Jul 10, 2007
Hello, All,
Here's the query I'm attempting to execute:
Code:
SELECT LEA, Count(SSN)
FROM WorkData2003_04.dbo.Students --Database and Table Name
WHERE Grade_Level='10' AND SSN NOT IN(
SELECT SSN
FROM WorkData2003_04.dbo.Students --Database and Table Name
WHERE Grade_Level='09')
However, SQL returns the following error:
Msg 8120, Level 16, State 1, Line 1
Column 'WorkData2003_04.dbo.Students.lea' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
I'm trying to generate a count of SSNs by LEA (LEA is the same thing as a school) that exist one school year but do not exist in the next school year (essentially students that transfer OUT of a school district).
Could someone provide assistance? I think I need to incorporate the HAVING clause but I'm not for sure...
Thanks!
Cody
View 6 Replies
View Related
Jun 22, 2004
I'm trying to write a report and need to group columns that are alike.
For example.
DeptID JobTitle
40344 Sales Clerk
1st Assistant
Store Manager
40666 Sales Clerk
2nd Assistant
Store Manager
Sorry, it will not output correctly, I hope you get what I'm trying to do.
I can get the results above but it puts the deptid for each job title. I do not want it. Any help will be appreciated. Thanks in advance.
View 6 Replies
View Related
Nov 15, 2005
Hi !
I have a log table like this :
UserID LoginDate
------ --------------
31 2005-11-01
31 2005-11-05
8 2005-11-02
31 2005-11-02
7 2005-11-04
I need to get the LAST login date for each user as the following result :
7 2005-11-04
8 2005-11-02
31 2005-11-05
Can someone help me please ?
Thanks !
View 2 Replies
View Related
Apr 19, 2008
I have 2 columns
RecordDate(DateTime)
Quantity(Int)
I would like to group the data quarter wise like,
Quarter 1 500
Quarter 2 340
Quarter 3 450
Quarter 4 400
Note: Say quarters are fixed from Jan-Mar,Apr-Jun etc.,
Prakash.P
The secret to creativity is knowing how to hide your sources!
View 2 Replies
View Related
Feb 23, 2006
I am writing a report from an historical database that uses posting_times. The way the posting works is if something has a posting time of 01/01/97 00:00:00 it means that the record covers from 12/31/96 00:00:00 to 01/01/97 00:00:00.
This is where my problem is at. The report i am writing needs to be grouped by Month. Before i figured out how the posting dates worked i was using ... DATEPART(month, posting_time) AS monthDate ... for grouping purposes in the report.
Now that i have figured out how the posting dates work i am at a total loss as how to group this. I am using SQL Reporting Services 2000 to write this report.
Any help would be greatly appreciated.
Thanks
Mitch
View 5 Replies
View Related
Mar 5, 2007
Is it possible to return just the top row of each group within a query result?
Par example, if I have a query that returns a list of products, grouped by order date and product name and ordered by date, name desc
How can I just get back the top row within each date grouping so that I can list the latest prod order per prod?
Thank you for any tips!
--PhB
View 20 Replies
View Related
Sep 19, 2007
its showing the promotion group not grouped right can you help
--#ttTransaction
SELECT ShipToID, Trans.StoreID, TransactionNumber, BatchNumber, [Time], CustomerID, CashierID,
CASE WHEN Trans.StoreID IN (172,173) THEN Total*CONVERT(FLOAT,(SELECT Value FROM DelSol.dbo.Parameter WHERE ID = 4))
ELSE CASE WHEN Trans.StoreID = 113
THEN CASE WHEN [Time] < '5/21/2005' THEN Total*CONVERT(FLOAT,(SELECT Value FROM DelSol.dbo.Parameter WHERE ID = 4))
ELSE Total END
ELSE Total END END AS Total,
CASE WHEN Trans.StoreID IN (172,173) THEN SalesTax*CONVERT(FLOAT,(SELECT Value FROM DelSol.dbo.Parameter WHERE ID = 4))
ELSE CASE WHEN Trans.StoreID = 113
THEN CASE WHEN [Time] < '5/21/2005' THEN SalesTax*CONVERT(FLOAT,(SELECT Value FROM DelSol.dbo.Parameter WHERE ID = 4))
ELSE SalesTax END
ELSE SalesTax END END AS SalesTax,
Comment, ReferenceNumber,
Status, ExchangeID, ChannelType, RecallID, RecallType,
CASE WHEN Trans.[Time] >= SO.ShiftDate THEN 'Same' ELSE 'New' END AS SalesType
INTO #ttTransaction
FROM QSCHQ.dbo.[Transaction] Trans
LEFT JOIN Reporting.dbo.RetailSalesComparison_StoreOpenings SO ON Trans.StoreID = SO.StoreID
WHERE YEAR([Time]) >= YEAR(GETDATE())-1
--#ttTransactionEntry
SELECT TE.Commission,
CASE WHEN TE.StoreID IN (172,173) THEN TE.Cost*CONVERT(FLOAT,(SELECT Value FROM DelSol.dbo.Parameter WHERE ID = 4))
ELSE CASE WHEN TE.StoreID = 113
THEN CASE WHEN [Time] < '5/21/2005' THEN TE.Cost*CONVERT(FLOAT,(SELECT Value FROM DelSol.dbo.Parameter WHERE ID = 4))
ELSE TE.Cost END
ELSE TE.Cost END END AS Cost,
CASE WHEN TE.StoreID IN (172,173) THEN TE.FullPrice*CONVERT(FLOAT,(SELECT Value FROM DelSol.dbo.Parameter WHERE ID = 4))
ELSE CASE WHEN TE.StoreID = 113
THEN CASE WHEN [Time] < '5/21/2005' THEN TE.FullPrice*CONVERT(FLOAT,(SELECT Value FROM DelSol.dbo.Parameter WHERE ID = 4))
ELSE TE.FullPrice END
ELSE TE.FullPrice END END AS FullPrice,
TE.StoreID, TE.[ID], TE.TransactionNumber, TE.ItemID,
CASE WHEN TE.StoreID IN (172,173) THEN TE.Price*CONVERT(FLOAT,(SELECT Value FROM DelSol.dbo.Parameter WHERE ID = 4))
ELSE CASE WHEN TE.StoreID = 113
THEN CASE WHEN [Time] < '5/21/2005' THEN TE.Price*CONVERT(FLOAT,(SELECT Value FROM DelSol.dbo.Parameter WHERE ID = 4))
ELSE TE.Price END
ELSE TE.Price END END AS Price,
TE.PriceSource, TE.Quantity, TE.SalesRepID, TE.Taxable, TE.DetailID, TE.Comment,
TE.AutoID, TE.DiscountReasonCodeID, TE.ReturnReasonCodeID, TE.TaxChangeReasonCodeID,
TE.SalesTax, TE.QuantityDiscountID
INTO #ttTransactionEntry
FROM QSCHQ.dbo.TransactionEntry TE
INNER JOIN #ttTransaction Trans
ON TE.StoreID = Trans.StoreID
AND TE.TransactionNumber = Trans.TransactionNumber
WHERE YEAR([Time]) >= YEAR(GETDATE())-1
--#ttTransactionWithPesoConversionAndCustomerAccount
SELECT Trans.StoreID, QSTStore.StoreGroupID, Trans.TransactionNumber, Trans.[Time], Customer.AccountNumber, Customer.Company,
Trans.Total, Trans.SalesTax, Trans.CashierID, Trans.SalesType
INTO #ttTransactionWithPesoConversionAndCustomerAccount
FROM #ttTransaction Trans
INNER JOIN QSCHQ.dbo.Customer Customer ON Trans.CustomerID = Customer.ID AND 1 = Customer.GlobalCustomer
INNER JOIN QSCHQ.dbo.QSTStore QSTStore ON Trans.StoreID = QSTStore.StoreID
UNION ALL
SELECT Trans.StoreID, QSTStore.StoreGroupID, Trans.TransactionNumber, Trans.[Time], Customer.AccountNumber, Customer.Company,
Trans.Total, Trans.SalesTax, Trans.CashierID, Trans.SalesType
FROM #ttTransaction Trans
INNER JOIN QSCHQ.dbo.Customer Customer ON Trans.CustomerID = Customer.ID AND Trans.StoreID = Customer.StoreID AND 1 <> Customer.GlobalCustomer
INNER JOIN QSCHQ.dbo.QSTStore QSTStore ON Trans.StoreID = QSTStore.StoreID
UNION ALL
SELECT Trans.StoreID, QSTStore.StoreGroupID, Trans.TransactionNumber, Trans.[Time], Customer.AccountNumber, Customer.Company,
Trans.Total, Trans.SalesTax, Trans.CashierID, Trans.SalesType
FROM #ttTransaction Trans
LEFT JOIN QSCHQ.dbo.Customer Customer ON Trans.CustomerID = Customer.ID AND Trans.StoreID = Customer.StoreID
INNER JOIN QSCHQ.dbo.QSTStore QSTStore ON Trans.StoreID = QSTStore.StoreID
WHERE Customer.[ID] IS NULL
AND Trans.CustomerId < 100000
UNION ALL
SELECT Trans.StoreID, QSTStore.StoreGroupID, Trans.TransactionNumber, Trans.[Time], Customer.AccountNumber, Customer.Company,
Trans.Total, Trans.SalesTax, Trans.CashierID, Trans.SalesType
FROM #ttTransaction Trans
LEFT JOIN QSCHQ.dbo.Customer Customer ON Trans.CustomerID = Customer.ID
INNER JOIN QSCHQ.dbo.QSTStore QSTStore ON Trans.StoreID = QSTStore.StoreID
WHERE Customer.[ID] IS NULL
AND Trans.CustomerId > 100000
--#ttRetailSales_ByStore_ByCustomer_ByDay
SELECT CONVERT(DATETIME, CONVERT(CHAR, [Time], 101)) AS [Date],
Trans.StoreID, Trans.StoreGroupID,
Trans.AccountNumber, Trans.Company,
SUM(TE.Price*TE.Quantity) AS Sales,
COUNT(DISTINCT Trans.TransactionNumber) AS TRXCount,
SUM(TE.Quantity) AS UnitsSold, Trans.SalesType
INTO #ttRetailSales_ByStore_ByCustomer_ByDay
FROM #ttTransactionWithPesoConversionAndCustomerAccount Trans
INNER JOIN #ttTransactionEntry TE
ON Trans.StoreID = TE.StoreID AND Trans.TransactionNumber = TE.TransactionNumber
WHERE (Trans.Total - Trans.SalesTax) <> 0
GROUP BY Trans.AccountNumber, Trans.StoreGroupID, CONVERT(DATETIME, CONVERT(CHAR, Trans.[Time], 101)),
Trans.StoreID, Trans.Company, Trans.SalesType
-- DROP TABLE #ttTransaction
-- DROP TABLE #ttTransactionEntry
-- DROP TABLE #ttTransactionWithPesoConversionAndCustomerAccount
-- ***** #ttTransGroup *****
SELECT [Date], PromotionGroupID,AccountNumber, SUM(Total) AS Total, SUM(TRXCount) AS TRXCount, SalesType
INTO #ttTransGroup
FROM
(SELECT [Date],
QSTStore.PromotionGroupID, Trans.AccountNumber,
Sales AS Total,
TRXCount, SalesType
FROM #ttRetailSales_ByStore_ByCustomer_ByDay Trans
INNER JOIN QSCHQ.dbo.QSTStore QSTStore ON Trans.StoreID = QSTStore.StoreID
WHERE Trans.AccountNumber LIKE 'C-%'
UNION ALL
SELECT TransactionDate AS [Date], QSTStore.PromotionGroupID, AccountNumber, SUM(Amount) AS Total, 0 AS TRXCount,
CASE WHEN QuickSellSalesAdjustment.[TransactionDate] >= SO.ShiftDate THEN 'Same' ELSE 'New' END AS SalesType
FROM DelSol.dbo.QuickSellSalesAdjustment QuickSellSalesAdjustment
INNER JOIN QSCHQ.dbo.QSTStore QSTStore ON QuickSellSalesAdjustment.StoreID = QSTStore.StoreID
LEFT JOIN Reporting.dbo.RetailSalesComparison_StoreOpenings SO ON QuickSellSalesAdjustment.StoreID = SO.StoreID
WHERE YEAR(TransactionDate) >= YEAR(GETDATE())-1
GROUP BY AccountNumber, QSTStore.PromotionGroupID, TransactionDate,
CASE WHEN QuickSellSalesAdjustment.[TransactionDate] >= SO.ShiftDate THEN 'Same' ELSE 'New' END) ttTemp
GROUP BY AccountNumber, PromotionGroupID, [Date], SalesType
HAVING SUM(ttTemp.Total) <> 0
-- ***** #ttCSVF *****
SELECT CSVFlag.TransactionDate, CSVFlag.StoreGroupID, CSVFlag.AccountNumber, CSVFlagType.[Description]
INTO #ttCSVF
FROM DelSol.dbo.CruiseShipVisitFlag AS CSVFlag
INNER JOIN DelSol.dbo.CruiseShipVisitFlagType AS CSVFlagType ON CSVFlagType.ID = CSVFlag.FlagTypeID
-- ***** Main *****
SELECT ttTransGroup.[Date] as TransactionDate,
QSTPromoStoreGroup.[ID] AS PromoGroupID, QSTPromoStoreGroup.StoreGroup AS PromoGroup,
ttTransGroup.AccountNumber AS AccountNumber, CruiseShip.ShipName AS ShipName,
CruiseShipGroup.[Description] AS ShipLine, CruiseShipCompany.[Description] AS PortLecturerCompany,
Sum(ttTransGroup.Total) AS GroupSales,
(CSVP.AdjustedProjection) AS Projection,
CruiseShip.Capacity, CASE WHEN CruiseShip.Capacity = 0 THEN 0 ELSE ttTransGroup.Total/CruiseShip.Capacity END AS ASPP,
CASE WHEN CONVERT(DECIMAL, CruiseShip.Capacity) = 0 THEN 0 ELSE CONVERT(DECIMAL, ttTransGroup.TRXCount)/CONVERT(DECIMAL, CruiseShip.Capacity) END AS Yield,
ttTransGroup.TRXCount, CASE WHEN ttTransGroup.TRXCount=0 THEN 0 ELSE ttTransGroup.Total/ttTransGroup.TRXCount END AS ADPT,
CruiseShipPortLecturer.[Name] AS PortLecturer,
CSVF.[Description] AS Flag, ttTransGroup.SalesType
FROM QSCHQ.dbo.QSTPromoStoreGroup QSTPromoStoreGroup
INNER JOIN #ttTransGroup ttTransGroup ON QSTPromoStoreGroup.[ID] = ttTransGroup.PromotionGroupID
INNER JOIN DelSol.dbo.CruiseShip CruiseShip ON ttTransGroup.AccountNumber = CruiseShip.AccountNumber
INNER JOIN DelSol.dbo.CruiseShipCompany CruiseShipCompany ON CruiseShip.PromotionCompany = CruiseShipCompany.[ID]
INNER JOIN DelSol.dbo.CruiseShipGroup CruiseShipGroup ON CruiseShip.GroupID = CruiseShipGroup.[ID]
LEFT JOIN DelSol.dbo.CruiseShipPortLecturer CruiseShipPortLecturer
ON CruiseShip.AccountNumber = CruiseShipPortLecturer.AccountNumber
AND ttTransGroup.[Date] BETWEEN CruiseShipPortLecturer.StartDate
AND CASE WHEN CruiseShipPortLecturer.EndDate IS NULL THEN '12/31/2099' ELSE CruiseShipPortLecturer.EndDate END
LEFT JOIN DelSol.dbo.CruiseShipVisitProjection CSVP
ON CSVP.TransactionDate= ttTransGroup.[Date]
AND CSVP.StoreGroupID = QSTPromoStoreGroup.[ID]
AND CSVP.AccountNumber = ttTransGroup.AccountNumber
LEFT JOIN #ttCSVF CSVF
ON CSVF.TransactionDate = ttTransGroup.[Date]
AND CSVF.StoreGroupID = QSTPromoStoreGroup.[ID]
AND CSVF.AccountNumber = ttTransGroup.AccountNumber
WHERE QSTPromoStoreGroup.ReceivesCruiseShips = 1
AND CSVF.[Description] IS NULL
Group By ttTransGroup.AccountNumber, QSTPromoStoreGroup.[ID],QSTPromoStoreGroup.StoreGroup,
ttTransGroup.[Date],
CruiseShip.ShipName,
CruiseShipGroup.[Description], CruiseShipCompany.[Description],
(CSVP.AdjustedProjection),
CruiseShip.Capacity, CASE WHEN CruiseShip.Capacity = 0 THEN 0 ELSE ttTransGroup.Total/CruiseShip.Capacity END,
CASE WHEN CONVERT(DECIMAL, CruiseShip.Capacity) = 0 THEN 0 ELSE CONVERT(DECIMAL, ttTransGroup.TRXCount)/CONVERT(DECIMAL, CruiseShip.Capacity) END,
ttTransGroup.TRXCount, CASE WHEN ttTransGroup.TRXCount=0 THEN 0 ELSE ttTransGroup.Total/ttTransGroup.TRXCount END,
CruiseShipPortLecturer.[Name],
CSVF.[Description], ttTransGroup.SalesType
Order by QSTPromoStoreGroup.StoreGroup
View 3 Replies
View Related
Jan 20, 2008
SQL2000. I have a table as follows. Table shows a log of solutions posted by agents. For example, Ticket#5 was replied once by each agent A,B and C.
==========================
ticket_number || agent || solution
==========================
5 || A || test
5 || B || test
5 || C || test
7 || B || test
7 || C || test
8 || C || test
9 || B || test
I need to find out number of all ticket solutions/counts (how many ticket was touched by all agents) but in format related to the single agent:
AGENT TICKET_NUMBER COUNT
A 5 3
B 5 3
C 5 3
B 7 2
C 7 2
.....
How could I achieve this?
Thank you much!
Julia
View 7 Replies
View Related
Jan 6, 2008
Hi
I have created a table and linked it to a dataset and grouped the data based on a field called SYSTEM.
Now in the group footer I have to display summary values for each system from another dataset.
But it always gives me the First Value in that. That is for all the groupings I get the summary value for the first system
only. How do I go about this.
Thanks
Sai
View 2 Replies
View Related
Dec 21, 2006
Hi,
I have a stored procedure which is returning results in the following format:
No.of substances Count
1 29
2 89
3 876
.. ..
15 56
16 89
Now i need to display like this:
No.of substances Count %
1 20
2 89
.. ..
>=9 8766
Total
All the substances which are >=9 have display no.of substances =>9 and Count is sum of all counts which have the no.of substances>=9
How to achieve this
Thanks in advance
View 1 Replies
View Related