Hello SQL and Crystal Reports friends,I am trying to make a report and need some help please.It is a helpdesk database. Jobs are logged, and then closed. Each ofthese events is timestamped in the database in the date fields“DateLogged” and “DateClosed”JanFebMarAprNewClosedNewClosedNewClosedNewClosed10 51362364525etc.I am trying to create a crosstab style report that will show each monthof the year along the top, and then the number of jobs logged and closedduring that month. The problem I am having is that when Crystal Groupsby the month, you have to specify a date field for the grouping. If Iselect “DateLogged”, then the crosstab will accurately show all of thejobs logged for that month, but is not correct for the jobs closedduring that month. The problem is that is counting the number of jobsthat were both logged AND closed during the grouped month.Can anyone see how such a report is possible?Furthermore, I would like to be able to calculate how many jobs wereopen at the start of the month, as well as at the end of the month.Thank you for your help.*** Sent via Developersdex http://www.developersdex.com ***Don't just participate in USENET...get rewarded for it!
I need to perform caculations on two date columns using datediff. The issue I have is that some of the date columns only have mm/yyyy. When this occurs I need to change the value to mm/dd/yyyy and insert 15 as the dd.My caculations are as follows without the required modification above.
DATEDIFF(YY, DOB, Start_DATE) - CASE WHEN Start_DATE >=DateAdd(yy,DateDIFF(yy,DOB,Start_DATE), DOB) THEN 0 ELSE 1 END AS Age,
I am trying to transfer 200 txt files into SQL server by using query analyzer. The command is 'Bulk insert [tableName] from 'pathfilename.txt' However, I need to read and modifiy the txt file. I am new to SQL server but I believe there must be some one who is a wizard can do what I want easily.
Thank you for the help in advance!
Here is the raw data layout, which is comma delimited. BDate 1/1/1990 BDate 1/1/1990 BDate 1/1/1990 BDate 1/1/1990 Edate 1/1/2005 Edate 1/1/2005 Edate 1/1/2005 Edate 1/1/2005 Fq D Fq D Fq D Fq D Date R P M E D Date R P M E D Date R P M E D Date R P M E D 1/1/90 1 2 3 4 5 1/1/90 2 3 4 5 6 1/1/90 3 4 5 6 7 1/1/90 4 5 6 7 8 2 3 4 5 6 1 2 3 4 5 3 4 5 6 7 6 7 8 9 1 1/1/05 ...... 1/1/05 .... 1/1/05 ..... 1/1/05 .....
This is the desired output after load into the table, which is tacking each repeating block on top of each other. Date R P M E D 1/1/90 1 2 3 4 5 2 3 4 5 6 1/1/05 ...... 1/1/90 2 3 4 5 6 2 3 4 5 6 1/1/05 ...... 1/1/90 3 4 5 6 7 3 4 5 6 7 1/1/05 ...... 1/1/90 4 5 6 7 8 6 7 8 9 1 1/1/05 ......
Hi all I'm transferring some Access queries to SQL server and the crosstabs don't want to work, can anyone shed any light on the query below.
Thanks.
TRANSFORM Min(tCompany.cCompanyName) AS CompanyName SELECT tProjContacts.ProjectID FROM tCompany INNER JOIN (tProjContacts INNER JOIN tCompanyType ON tProjContacts.CoTypeId = tCompanyType.CoTypeId) ON tCompany.CompanyID = tProjContacts.CompanyID WHERE (((tCompanyType.CoType) Like "*topo*" Or (tCompanyType.CoType) Like "*ground*")) GROUP BY tProjContacts.ProjectID PIVOT tCompanyType.CoType;
Hello, I have a table called #table1 which is populated as in the example below. I would like to write a selectinsert statement based on #table1 that populates #table2 like in the #table2 example. Note #table2 is a fixed table that follows the structure below.
Can any of you T-SQL gurus help me with my problem? Any help will be most appreciated. Thanks
Insert into #table1 select '012345','2008-04-19 00:00:00.000' , '01', '06', '05', null, null UNION all select '012345','2008-04-20 00:00:00.000' , '01', '07', '05', '07', '03' UNION all select '012345','2008-04-21 00:00:00.000' , '01', '06', null, null, null UNION all select '012345','2008-04-22 00:00:00.000' , '01', '02', '05', '07', null UNION all select '012345','2008-04-23 00:00:00.000' , '03', '06', null, null, null UNION all select '987654','2008-04-21 00:00:00.000' , '19', '21', null, null, null UNION all select '987654','2008-04-22 00:00:00.000' , '01', '02', '05', '16', null UNION all select '987654','2008-04-23 00:00:00.000' , '03', '06', null, null, null
select * from #table1
--This is the table i would like to insert my data into CREATE TABLE #table2 --max of 5 orders in 1 day --it does not matter what date the date order was made the 1st date would appear in dateorder1 and so on... ( custID nvarchar(6), dateorder1 [datetime] NULL, order1_1 nvarchar(2), order1_2 nvarchar(2), order1_3 nvarchar(2), order1_4 nvarchar(2), order1_5 nvarchar(2), dateorder2 [datetime] NULL, order2_1 nvarchar(2), order2_2 nvarchar(2), order2_3 nvarchar(2), order2_4 nvarchar(2), order2_5 nvarchar(2), dateorder3 [datetime] NULL, order3_1 nvarchar(2), order3_2 nvarchar(2), order3_3 nvarchar(2), order3_4 nvarchar(2), order3_5 nvarchar(2), dateorder4 [datetime] NULL, order4_1 nvarchar(2), order4_2 nvarchar(2), order4_3 nvarchar(2), order4_4 nvarchar(2), order4_5 nvarchar(2), dateorder5 [datetime] NULL, order5_1 nvarchar(2), order5_2 nvarchar(2), order5_3 nvarchar(2), order5_4 nvarchar(2), order5_5 nvarchar(2) )
I am a neewbie to SQL 7 and having previously used Access for some time.. I have a table with a date field in a want to create a table with the values filling columns in another table by month ie April,may ,Jun and so on. Ia m using the Month function to get the month number but I dont know how to crosstab this into the relevant columns in the new table...I thinks DTS is the way and do a transformation on the month field but am struglling at the mo...Any help greatfully appreciated...
I need to accomplish the turning column data into row data via SQL. I can sorta get what I want with creating the report as a matrix report. However, I always seem to need one little thing to happen to shape my data as I need it. Anyway, here goes...
I have a table with 4 columns
UNIQUE | Code | FieldID | CustomField
The Code column is the customer code. FieldID numbers 1-100 and CustomField has string data.
My problem. I need to be able to choose ALL Customers [Code] where FieldID/s ="6", "7" & "8" and the CustomField rowdata corresponding to the FieldID data. BUT I then need to be able to use a daterange parameter on any row with a FieldID of "6" but that is not a datetime format it is in a string format.
Currently my SQL is:
SELECT [Unique ID], Code, [Field ID] AS IUdate, [Field ID] AS IUNote, [Field ID] AS IUReq, [Custom Field]
FROM dbo.[Customer Custom Field]
WHERE (Code = '07-8111')AND ([Field ID] = 6) OR (Code = '07-8111')AND ([Field ID] = 7) OR (Code =
'07-8111')AND ([Field ID] = 8)
However, everytime I try to run a daterange against, I get all kinds of data I don't need because the parameter is running against all the fields and NOT just the stringdate.
My idea is to convert the column data into row data (like a crosstab query) to sharpen it up for parameter ranges.
Is there something i am missing here? Can someone point me in the right direction?
Is there a way to write Crosstab query in SQL 7.0.
I have a Table which has partner, usernames and the city they are from, apart from other fields. I have another table which tracks the user activity on a day by number of visits to the web site. What i want is like this :-
Date Total Visits Atlanta Connecticut .... .... ....
I.E. I wan't the city names to appear as columns. The main catch here is that this data is for a given partner. So the city names could be different for different users from different partners. i.e. city names have to be generated on the fly by looking at the partner table and then by getting all its users and seeing what all are the cities involved.
I am trying to run a report off a crosstab query. The report calls for columns A - F, which are returned from the crosstab query. The only problem is that at times some of the columns are not returned by the query because there is no data associated with them. The report asks for column X, and no such columns exists in the query result; thus, an error is generated. My question is: how do I deal with this problem? I would like to avoid having to build the report from scratch. Is there some way that at runtime I could programatically tell the report to ignore these fields?
I have a table called Ideas and a table called Users_Ideas. In Users_Ideas, there can be up to four rows referencing Ideas with a foriegn key. I need to select all rows from Ideas and for each Idea display the users associated with it.
Total is the total number of alerts for the server between the two dates. Of course, there are many servers, and the number of alert names varies over time which means i can't use "case when...".
Is this possible??? Would be extremely thankful for any help!
I'm trying to port a dymanically renderred form from a .mdb to a .adp. In the Access .mdb. The form is a representation of a crosstab query with unknown column headings (hence, the need for the form to be dynamically rendered at runtime).
I tried to port the crosstab from the .mdb to a stored procedure, but SQL Server doesn't like TRANSFORM, and perhaps the PIVOT as well. How do you do this in sql server?:
TRANSFORM Count(d.CAR_INIT) AS CountOfCAR_INIT SELECT b.WKLD_SEQ, c.TRN_ID, c.TRK_NBR FROM ((TSA_HS_MPCT_CNT a INNER JOIN TSA_HS_COMB2 b ON a.RECC_COMB_ID = b.COMB_ID) INNER JOIN TSA_HS_WKLD c ON b.WKLD_ID = c.WKLD_ID) INNER JOIN TSA_HS_OBJ_TRN d ON c.WKLD_ID = d.WKLD_ID GROUP BY b.WKLD_SEQ, c.TRN_ID, c.TRK_NBR PIVOT d.LST_HMP_DTM + d.OBJ_DEP_TRN
Hi, I have tried with the solutions available in the links provided by Pootle,but still I think I have to go a long way.My main problem is with the second aggregate column of previous year. Let me put it again....
But I can't bring the previous year aggregate column ,i.e 2005 in the above case.
So can you suggest me a way or direction to acheive that?
Any help would be really appreciated. BTW,Pootle gave these links in my previous post... link1 (http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_21820764.html#16500817) Link2 (http://www.sqlteam.com/item.asp?ItemID=2955)
Hi I have table called MyTable that has 3 columns (City , Brand, Price) I want to select from this table in Cross Tab format i.e. My table has CityBrandPrice LondonDELL1227 LondonToshiba1100 LondonAcer1007 LondonHP1467 LondonIBM1193 SydneyToshiba2100 SydneyAcer2219 SydneyApple2589 SydneyVAIO2122 SydneyHP1929 SydneyIBM2877 TokyoToshiba7200 TokyoAcer5299 TokyoCOMPAQ9200 TokyoIBM8779 TokyoHP6286 ParisDELL1670 ParisApple1825 ParisVAIO1267 ParisHP1882 ParisCOMPAQ1636 ParisIBM1332 NewYorkDELL2000 NewYorkToshiba1288 NewYorkAcer2333 NewYorkApple2299 NewYorkVAIO2327
__________________________________
i want the select statment result to be like this DELLToshibaAcerHPIBMAppleVAIOCOMPAQ London12271100100714671193N/AN/AN/A SydneyN/A2100221919292877N/AN/AN/A TokyoN/A7200529962868779N/AN/A9200 Paris1670N/AN/A18821332182512671636 NewYork200012882333N/AN/A22992327N/A
City & Brand can be anything so i will not be able to hard code them in my Select.
Currently working on a Attendance System project . Iam storing the data in table against the employee code, date and status (basically a rowwise data).
Would require a query which can generate a cross-tab display with Employee Codes (on X axis), Dates (on Y-Axis) and with the Attendance Status.
The sample data for the same is as follows:
EmpCode Att_Date Att_Status ------- -------- ---------- 001 01/01/2007 P 001 01/02/2007 A .. ... .. 001 01/31/2007 P
002 01/01/2007 P . . . . . . . . .
Would require the output as..
EmpCode 01/01/2007 01/02/2007 ...... 01/31/2007 ------- ---------- ---------- ---------- 001 P A P 002 A P P . . . . . . . . . . . .
Can someone show me how to write a query to convert this:Year, Account, Qtr1, Qtr2, Qtr3, Qtr42004, 12345, 100, 200, 300, 4002005, 23456, 200, 300, 400, 500to this:Year, Account, Quarters, Amount2004, 12345, Qtr1, 1002004, 12345, Qtr2, 2002004, 12345, Qtr3, 3002004, 12345, Qtr4, 4002005, 23456, Qtr1, 2002005, 23456, Qtr2, 3002005, 23456, Qtr3, 4002005, 23456, Qtr4, 500So far I've only found examples which convert values to columns but notfor columns to values. TIA... AL
Dear friends,I wonder if exist a way to make crosstab queries in SQL Serverlike those in Access without "external" programming. Does theSQL Server supports the "TRANSFORM" SQL-extension?Thanks in advance, Sotiris.
I have two tables Bill and Location.Bill(location_id int,prod_period datetime,consumption float,demand float)Location(location_id int,location_name varchar(45))I want to create a stored procedure that takes a parameter of @year. Ibasically want the procedure to return results that show locationswhere consumption and/or demand IS NULL or 0 for each month throughouta given year. I would like my results to look something like this:location_id year Jan Feb Mar Apr May Jun Jul Aug Sept OctNov Dec1 2005 0 0 02 2005 0 0 0 03 2005 0 0If data does exist for consumption or demand, I would like to show it,however I am really interested in the locations that have no dataassociated with them.Any ideas of how I can accomplish this?
I re-designed a predecessor's database so that it is more properlynormalized. Now, I must migrate the data from the legacy system intothe new one. The problem is that one of the tables is a CROSSTABTABLE. Yes, the actual table is laid out in a cross-tabular fashion.What is a good approach for moving that data into normalized tables?This is the original table:CREATE TABLE [dbo].[Sensitivities]([Lab ID#] [int] NULL,[Organism name] [nvarchar](60) COLLATE SQL_Latin1_General_CP1_CI_ASNULL,[Source] [nvarchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,[BACITRACIN] [nvarchar](2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,[CEPHALOTHIN] [nvarchar](2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,[CHLORAMPHENICOL] [nvarchar](2) COLLATE SQL_Latin1_General_CP1_CI_ASNULL,[CLINDAMYCIN] [nvarchar](2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,[ERYTHROMYCIN] [nvarchar](2) COLLATE SQL_Latin1_General_CP1_CI_ASNULL,[SULFISOXAZOLE] [nvarchar](2) COLLATE SQL_Latin1_General_CP1_CI_ASNULL,[NEOMYCIN] [nvarchar](2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,[OXACILLIN] [nvarchar](2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,[PENICILLIN] [nvarchar](2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,[TETRACYCLINE] [nvarchar](2) COLLATE SQL_Latin1_General_CP1_CI_ASNULL,[TOBRAMYCIN] [nvarchar](2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,[VANCOMYCIN] [nvarchar](2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,[TRIMETHOPRIM] [nvarchar](2) COLLATE SQL_Latin1_General_CP1_CI_ASNULL,[CIPROFLOXACIN] [nvarchar](2) COLLATE SQL_Latin1_General_CP1_CI_ASNULL,[AMIKACIN] [nvarchar](2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,[AMPICILLIN] [nvarchar](2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,[CARBENICILLIN] [nvarchar](2) COLLATE SQL_Latin1_General_CP1_CI_ASNULL,[CEFTAZIDIME] [nvarchar](2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,[GENTAMICIN] [nvarchar](2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,[OFLOXACIN] [nvarchar](2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,[POLYMYXIN B] [nvarchar](2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,[MOXIFLOXACIN] [nvarchar](2) COLLATE SQL_Latin1_General_CP1_CI_ASNULL,[GATIFLOXACIN] [nvarchar](2) COLLATE SQL_Latin1_General_CP1_CI_ASNULL,[SENSI NOTE] [nvarchar](255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL) ON [PRIMARY]
I cant figure out what is going wrong here. I created this query to be able to show values across periods , and put it inside of a table instead of a matrix, for easier totals and subtotals. but for some reason my subquery is not pullin up the right amounts for "Goal Amount". The fields i have labeled as Period_1 , period_2 and so on work just fine. But the goals are not coming up with the same number as in the Sub query, if i ran it by its self. I dont know if maybe its the join, or what. but for some reason the numbers are way high then they should be. am i doing something wrong. Please let me know if i need to give more information.
This is what the output looks like now: 0.0000 0.0000 0.0000 4516182.0000 5569957.8000 2559169.8000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 3915126.9500 3275922.5500 1598011.0000 4526861.2500 6880829.1000 3078265.6500 629010.4000 589697.2500 353818.3500 2218175.9000 1984683.7000 1517699.3000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
this is what it looks like in the subquery: 150539.4000 2008 1 80 12 150539.4000 2008 2 80 12 150539.4000 2008 3 80 12 39313.1500 2008 1 81 12 39313.1500 2008 2 81 12 39313.1500 2008 3 81 12 181074.4500 2008 1 82 12 181074.4500 2008 2 82 12 181074.4500 2008 3 82 12 116746.1000 2008 1 86 12 116746.1000 2008 2 86 12 116746.1000 2008 3 86 12 79900.5500 2008 1 87 12 79900.5500 2008 2 87 12 79900.5500 2008 3 87 12 the two numbers highlighted should have the same amounts.
Code Snippet
SELECT cusSales.Report_Level_Id AS Report_Level, cusSales.Customer_Sales_Summary_Year AS Year, Goals.Region_Key, Qry_Report_Level_Brand.Report_Level_Description, RC_DWDB_INSTANCE_1.dbo.Qry_Sales_Group_Dimension.Region_Name, SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 1 THEN cusSales.Customer_Sales_Summary_Amount ELSE 0 END) AS Period_1, SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 2 THEN cusSales.Customer_Sales_Summary_Amount ELSE 0 END) AS Period_2, SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 3 THEN cusSales.Customer_Sales_Summary_Amount ELSE 0 END) AS Period_3, SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 4 THEN cusSales.Customer_Sales_Summary_Amount ELSE 0 END) AS Period_4, SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 5 THEN cusSales.Customer_Sales_Summary_Amount ELSE 0 END) AS Period_5, SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 6 THEN cusSales.Customer_Sales_Summary_Amount ELSE 0 END) AS Period_6, SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 7 THEN cusSales.Customer_Sales_Summary_Amount ELSE 0 END) AS Period_7, SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 8 THEN cusSales.Customer_Sales_Summary_Amount ELSE 0 END) AS Period_8, SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 9 THEN cusSales.Customer_Sales_Summary_Amount ELSE 0 END) AS Period_9, SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 10 THEN cusSales.Customer_Sales_Summary_Amount ELSE 0 END) AS Period_10, SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 11 THEN cusSales.Customer_Sales_Summary_Amount ELSE 0 END) AS Period_11, SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 12 THEN cusSales.Customer_Sales_Summary_Amount ELSE 0 END) AS Period_12, SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 13 THEN cusSales.Customer_Sales_Summary_Amount ELSE 0 END) AS Period_13, SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 1 THEN Goal_Amount ELSE 0 END) AS GOAL_1, SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 2 THEN Goal_Amount ELSE 0 END) AS GOAL_2, SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 3 THEN Goal_Amount ELSE 0 END) AS GOAL_3, SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 4 THEN Goal_Amount ELSE 0 END) AS GOAL_4, SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 5 THEN Goal_Amount ELSE 0 END) AS GOAL_5, SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 6 THEN Goal_Amount ELSE 0 END) AS GOAL_6, SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 7 THEN Goal_Amount ELSE 0 END) AS GOAL_7, SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 8 THEN Goal_Amount ELSE 0 END) AS GOAL_8, SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 9 THEN Goal_Amount ELSE 0 END) AS GOAL_9, SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 10 THEN Goal_Amount ELSE 0 END) AS GOAL_10, SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 11 THEN Goal_Amount ELSE 0 END) AS GOAL_11, SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 12 THEN Goal_Amount ELSE 0 END) AS GOAL_12, SUM(CASE cusSales.Customer_Sales_Summary_Period WHEN 13 THEN Goal_Amount ELSE 0 END) AS GOAL_13 FROM RC_DWDB_INSTANCE_1.dbo.Tbl_Territory_In_Customer INNER JOIN RC_DWDB_INSTANCE_1.dbo.Tbl_Customer_Sales_Summary_Fiscal AS cusSales INNER JOIN Qry_Report_Level_Brand ON cusSales.Sub_Brand_Id = Qry_Report_Level_Brand.Sub_Brand_Id ON RC_DWDB_INSTANCE_1.dbo.Tbl_Territory_In_Customer.Customer_Code = cusSales.Customer_Code INNER JOIN RC_DWDB_INSTANCE_1.dbo.Qry_Sales_Group_Dimension ON RC_DWDB_INSTANCE_1.dbo.Tbl_Territory_In_Customer.Territory_Code = RC_DWDB_INSTANCE_1.dbo.Qry_Sales_Group_Dimension.Territory_Code FULL OUTER JOIN (SELECT SUM(cusSales.Customer_Sales_Summary_Amount) AS Goal_Amount, cusSales.Customer_Sales_Summary_Year AS Year, cusSales.Customer_Sales_Summary_Period AS Period, cusSales.Report_Level_Id, RC_DWDB_INSTANCE_1.dbo.Tbl_Territory_In_Region.Region_Key FROM RC_DWDB_INSTANCE_1.dbo.Tbl_Customer_Sales_Summary_Fiscal AS cusSales INNER JOIN RC_DWDB_INSTANCE_1.dbo.Tbl_Territory_In_Customer AS Tbl_Territory_In_Customer_1 ON cusSales.Customer_Code = Tbl_Territory_In_Customer_1.Customer_Code INNER JOIN RC_DWDB_INSTANCE_1.dbo.Tbl_Territory_In_Region ON Tbl_Territory_In_Customer_1.Territory_Code = RC_DWDB_INSTANCE_1.dbo.Tbl_Territory_In_Region.Territory_Code WHERE (cusSales.Customer_Sales_Summary_Year = 2008) AND (cusSales.Consolidated_Sales_Tables_Id = 8) and region_key=12 GROUP BY cusSales.Customer_Sales_Summary_Year, cusSales.Customer_Sales_Summary_Period, cusSales.Report_Level_Id, RC_DWDB_INSTANCE_1.dbo.Tbl_Territory_In_Region.Region_Key) AS Goals ON RC_DWDB_INSTANCE_1.dbo.Qry_Sales_Group_Dimension.Region_Key = Goals.Region_Key AND cusSales.Report_Level_Id = Goals.Report_Level_Id AND cusSales.Customer_Sales_Summary_Year = Goals.Year AND cusSales.Customer_Sales_Summary_Period = Goals.Period WHERE (cusSales.Customer_Sales_Summary_Year IN (2007, 2008)) AND (cusSales.Consolidated_Sales_Tables_Id = 6) AND (NOT (cusSales.Bill_Customer_Code IN ('11825', '11990', '11971'))) AND (cusSales.Report_Level_Id IN (78, 80, 81, 82, 86, 87)) AND (RC_DWDB_INSTANCE_1.dbo.Qry_Sales_Group_Dimension.Group_Name <> 'BREEDER') AND (RC_DWDB_INSTANCE_1.dbo.Qry_Sales_Group_Dimension.Group_Name <> 'OTHER') AND (RC_DWDB_INSTANCE_1.dbo.Qry_Sales_Group_Dimension.Group_Name <> 'Vet - Corporate') AND (RC_DWDB_INSTANCE_1.dbo.Qry_Sales_Group_Dimension.Group_Name <> 'export') AND (RC_DWDB_INSTANCE_1.dbo.Qry_Sales_Group_Dimension.Group_Name <> 'Vet - Other') AND (RC_DWDB_INSTANCE_1.dbo.Qry_Sales_Group_Dimension.Region_Key = 12) GROUP BY cusSales.Report_Level_Id, cusSales.Customer_Sales_Summary_Year, Goals.Region_Key, Qry_Report_Level_Brand.Report_Level_Description, RC_DWDB_INSTANCE_1.dbo.Qry_Sales_Group_Dimension.Region_Name