I have a date column that formated and i need to group by it, how do it do this? i get this error code:
Msg 8120, Level 16, State 1, Line 2
Column 'o.Initials' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
here is my query:
select * from(
SELECT CONVERT(VARCHAR(10), AITDate, 110) AS FormatDate
, TechInt as Initials
, [Drug]
,[Missed PT Notes]
,[Pt Same Name]
,[PT Family]
,[Wrong PT]
,[Wrong Ques. Asked]
,[DAW]
,[Rx/Refills Omitted]
,[Allergy]
,[Wrong Sig]
,[Strength]
,[Wrong PT Address]
,[Quantity]
,[SVQ]
,[Refills]
,[Write Date]
,[Wrong MD/MD Info]
,[Rx Should be Questioned]
,[TSTF],[Non-Link Image]
,[DC Date],[Days Supply]
,[No Call Card]
,[Order Count]
,[Credit Hold Procedure]
,[Routing]
,[Sig Typo]
,[Verse Missing/Wrong]
,[Right Drug Wrong Form]
,[Others]
from tblaitinfo
pivot (count(ercode) for ercode in ([Drug],[Missed PT Notes],[Pt Same Name],[PT Family],[Wrong PT],[Wrong Ques. Asked],[DAW],[Rx/Refills Omitted],[Allergy],[Wrong Sig],[Strength],[Wrong PT Address],[Quantity],[SVQ],[Refills],[Write Date],[Wrong MD/MD Info],[Rx Should be Questioned],[TSTF],[Non-Link Image],[DC Date],[Days Supply],[No Call Card],[Order Count],[Credit Hold Procedure],[Routing],[Sig Typo],[Verse Missing/Wrong],[Right Drug Wrong Form],[Others])) p
)o
group by formatdate
This is a report I'm trying to build in SQL Reporting Services. I can do it in a hacky way adding two data sets and showing two tables, but I'm sure there is a better way.
TheTable Order# Customer Status
STATUS has valid values of PROCESSED and INPROGRESS
The query I'm trying to build is Count of Processed and INProgress orders for a given Customer.
I can get them one at a time with something like this in two different datasets and showing two tables, but how do I achieve the same in one query?
Select Customer, Count (*) As Status1 FROM TheTable Where (Status = N'Shipped') Group By Customer
I am using a sql command to produce outputs having 3 columns Before running the sql I am spooling the output in .xls format But when I open the .xls file (i.e. the spooled file) data of all the 3 columns appear in a single column with blank spaces between them Is there a way by which I can ensure that each output column of the SQL appears in a seperate column in the excel Sheet
I need to create a "simple" sql query but have it formatted and then emailed to individuals. I am trying to convert over from Oracle but I am having a hard time getting the query to be formatted the way I want. Here is the select statement I tried to use with no luck with xp_sendmail:
SELECT ALARM ID, TIMESTAMP as TIME, CLASS, RESOURCE, P, L, F, ALARM_MESSAGE FROM ALARM_LOG WHERE ([TIMESTAMP] < GETDATE() - 1) ORDER BY [TIMESTAMP];
Here what the output should look like with the column headers underlined and then the column data (notice the column heading ALARM MESSAGE is on the next line before any data):
ALARM ID TIME CLASS RESOURCE P L F -------------------- ----------- ----- ---------------- - - - ALARM_MESSAGE ------------------------------------------------------------- B3_TEMP_ALM 02-02@11:21 ALARM BUILDING3_TEMP N G G BUILDING 3 TEMPERATURE ALARM, CALL SECURITY.
B5_TEMP_ALM 02-02@11:22 ALARM BUILDING5_TEMP N G G BUILDING 5 TEMPERATURE ALARM, CALL SECURITY.
How can I run the query and have it formatted and emailed out? What is the best way to accomplish this?
I am trying to output data from my sql table to an excel spreadsheet and send it by email which works fine, the problem is he wants the date to be in the format d-mmm-yy, which is easy to format in excel manually, but he do not want to do this manually. I tried to do this when I select the date from the table to spreadsheet, "select convert(char,value_date,106) from table", but this don't get transported to the excel spreadsheet, I get my results on the spread sheet as dd/mm/yy. Can you please help either to set the date on excel forever to be in this format "d-mmm-yy" or to force this output to excel
1). which category has how many regisrtantids (like 277 has how many registrantids) 2). group the registrants by category so that i can find which registrants are in category 277 for example)
Do I need to create a function which generates a table from csv ? I have created a function but not sure if it will work in this situation with IN clause.
I have a requirement from my users to be able to drill down for a single column in a matrix. I've been able to implement drilldown for all of the measures (all columns grouped at the same time) in my matrix but they now want to be able to group different columns independently of each other. In other words they want to be able to group the data in different columns by different things.
An example might make my question clearer, the report would need to look like this:
Client Name Sales - Costs + Revenue -
Client A + Europe + Middle East + Asia Pacific + $12,000,000 Products + Investments +
Client B + $77,000,000 $16,000,000 $9,000,000 $22,000,000 $8,000,000 $32,000,000
As you an see, the Sales measure has been expanded so it's grouped by region so the sales figures can be seen for all clients and the 3 regions. The revenue column has also been expanded/grouped so that you can see revenue figures for products and investments for all clients. Costs is not expanded but it could be by clicking on the '+' which would group the data in that column by something else. They have asked for more than 1 level of drilldown, so clicking on "Europe" above would allow another level for the sales measure which might be country. There will also be regular measure columns that are not drilldown/groupable columns.
I need to group data in a sql report by currency values. I have a report that shows part numbers and 4 columns making up manufacturing costs and then a 5th column showing total costs. I would like to add a 6th column that groups the total costs by ranges. The example would be, group all costs > 20000, group all costs 1000 > x > 20000 , and finally all costs < 1000.
TeamStatus T 1 Complete or Escalate T 2 Pick Up T 2 Resolve Case T 1 Pick Up T 1 Complete or Escalate T 1 Pick Up T 1 Complete or Escalate
I want to get he group based of Resolve Case value in Status Column. Anything before Resolve case will be considered as Group 1 and after Resolve Case status should be considered as Group 2. Below is desired new Group column,
Group TeamStatus Group 1 T 1Complete or Escalate T 2 Pick Up T 2 Resolve Case
Group 2 T 1Pick Up T 1Complete or Escalate T 1 Pick Up T 1 Complete or Escalate
I'm trying to divide two values from separate rows. Each row is a separate UNION statement.
2014-08-03 00:00:00.000NKBB (N) - Total Offers 1218 UNION (A) 2014-08-03 00:00:00.000NKBB (N) - With Lead 301 UNION (B) 2014-08-03 00:00:00.000NKBB (N) - Without Leads 917 UNION (C)
In the below example, I would like to divide KBB (N) - With Lead (UNION (B)/KBB (N) - Total Offers UNION (A)
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.
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.
I REALLY need to perform a JOIN and a GROUP BY on a CASE function column alias, but I'm receiving an "Invalid column name" error when attempting to run the query. Here's a snippet:
SELECT NewColumn= CASE WHEN Table1.Name LIKE '%FOO%' THEN 'FOO TOO' END, Table2.SelectCol2 FROM Table1 JOIN Table2 ON NewColumn = Table2.ColumnName GROUP BY NewColumn, Table2.SelectCol2 ORDER BY Table2.SelectCol2
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.
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.
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:
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_]
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
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.
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...
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.
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
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
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 .....