.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Usin SQL Pivot

Posted By:      Posted Date: October 10, 2010    Points: 0   Category :Sql Server

I have a table which has a source column, same records can be provided by different source, I want to be able to produce a table which shows this.

DM_FileURN PPN_0001 PPN_0002 PPN_0003 PPN_0004 PPN_0005 PPN_0006 PPN_0007 PPN_0008

PPN_0001 12 0 0 0 0 0 0 0

PPN_0002 0 10057 0 0 0 0 0 0

PPN_0003 10 0 3 0 0 0 0 0

PPN_0004 0 0 0 3 0 0 0 0

PPN_0005 0 0 0 0 3 0 0 0

PPN_0006 0 0 0 0 0 5 0 0

PPN_0007 0 0 0 8 0 0 9 0

PPN_0008 0 0 0 0 0 0 0 3

can i use pivot to show results as above?



View Complete Post

More Related Resource Links

How to authenticate local user usin ldap or non domain authentication



I created one application, and I need to authenticate local user. This user is the user who is login to his/her Personal Computer.. Main thing his that he/she does not in any DOMAIN... I want NON-DOMAIN authentication.. any how.... please help...

Pivot w/o aggregation...query not working

Hi all--Given this query, I need to make this query into a pivot table: select Personnel_id, First Name, Last Name, E-mail, Division, Region, Country, Manager, Question, Answer, Date Completed from #pivot where Question Answer 01. Received File No 02. Read File Yes 03. Signed File Yes ... Needs to look like this: Personnel_id First Name ... 01. Received File 02. Read File 03. Signed File ... Test01 Test No Yes Yes I have the following pivot query: SELECT [Personnel_id] ,[First Name] ,[Last Name] ,[Email] ,[Division] ,[Region] ,[Country] ,[Manager] ,[Question] ,[Answer] ,[Date Completed] FROM (SELECT [Personnel_id] ,[First Name] ,[Last Name] ,[Email] ,[Division] ,[Region] ,[Country] ,[Manager] ,[Question] ,[Answer] ,[Date Completed] FROM #pivot) topvt PIVOT (MAX([Personnel_id]) FOR Answer in ([1],[2], [3], [4], [5], [6], [7], [8] , [9], [10])) as pvt ORDER BY pvt.[Personnel_id] I get this error: Msg 207, Level 16, State 1, Line 83 Invalid column name 'Personnel_id'. Any ideas? Thanks!

Using Pivot to arranging data

Hello, I am attempting to optimize a selection query and I thought I would try a PIVOT. My question is simply is this the best way to do it? If not, why and what may be better? Please note the Tmstmp column is not necessarily spaced evenly like this example. Sample table:   Declare @temp table (Tmstmp datetime, Value integer ) INSERT INTO @temp (Tmstmp, Value) VALUES ('01/01/10',1) INSERT INTO @temp (Tmstmp, Value) VALUES ('01/02/10',2) INSERT INTO @temp (Tmstmp, Value) VALUES ('01/03/10',11) INSERT INTO @temp (Tmstmp, Value) VALUES ('01/04/10',1) INSERT INTO @temp (Tmstmp, Value) VALUES ('01/05/10',3) INSERT INTO @temp (Tmstmp, Value) VALUES ('01/06/10',5) INSERT INTO @temp (Tmstmp, Value) VALUES ('01/07/10',11) INSERT INTO @temp (Tmstmp, Value) VALUES ('01/08/10',1) INSERT INTO @temp (Tmstmp, Value) VALUES ('01/09/10',2) ;With CTE as ( SELECT t1.Tmstmp as StartDate, t2.Tmstmp as EndDate, t1.Value as Start_Val, t2.Value as End_Val, Row_Number() Over(Partition By t1.TmStmp ORDER BY DateDiff(day,t1.TmStmp,t2.TmStmp)) as Seq FROM @temp t1 INNER JOIN @temp t2 ON t2.Tmstmp > t1.Tmstmp WHERE t1.Value = 1 AND t2.Value = 11 ) SELECT StartDate, EndDate, [2] as TmStmp2, [3] as TmStmp3, [4] as TmStmp4, [5] as TmStmp5 FROM ( SELECT a.StartDate, a.EndDat

PIvot Table in SSRS 2008

Hi All, Is there any data Region (Pivot) in SSRS 2008 or higher version? Our requirement is to show the report like excel pivot gererated from a OLAP Cube where we can select or unselect any dimesion attribute or measures. Thanks, IndiaSQl  

SSAS Cube & Pivot table

Hello, I am connecting to my SSAS cube through excel Pivot table. I have the following questions: 1) I have a filter for Company. However, instead of selecting multiple companies from a drop down list, I would like to have a range e.g. Company between 100 and 200. We have this "Filter expression and operator" option in SSAS but I dont see in excel. 2) I have 90 users who will be using my cube via pivot tables. How do I automatically have the data in excel refresh automatically such that when the user comes in, in the morning and open the pivot table, they have the refreshed data. Instead of them manually refresh it as it runs the query for a long time. Thanks in advance for all your help and suggestions! KJ

Excel 2007 Pivot table OLAP- SSAS 2008 Error

Hi, I do have a strange issue with Excel 2007 pivot table report; the data source is SSAS 2008 cube. When refresh the excel 2007 report data using the 'Refresh All' or 'Refresh' button available under the Data menu, the below error is thrown. "The expression contains a function that cannot operate on a set with more than 4,294,967,296 tuples." After some analysis, the report works well on the below workaround, 1. Remove all the calculated measures from report (3 measures in this scenario) 2. Remove one row label (dimension attribute) from report But the measures, attributes are valid one from cube and it is required fields in the report. So, understand that removing few items is not at all a solution. The below workaround also works. 1. Check the 'Defer Layout Update' option from the Pivot Table Field List window. 2. Click on the Update button After that Unchecked the 'Defer Layout Update' option and apply the filter, etc in the report. The report works very well. But every time, we need to use the above work around after open the excel report. I have NO clue on this issue. Please help to resolve this issue. Thanks, Jey


Hello EveryOne,               I am making a monthly attendance details of all employees who is working in my company. I am using sql server management studio 2005.       My table is in this format. staffcode   name                                   date            Intime   Outtime Duration                         1               Amit                                  01-08-2010    00:00    00:00    00:00 1              Amit                                   02-08-2010    09:52    20:01    10:09 1&n

using Live Labs Pivot in SharePoint 2010

Hi, Any pointers to get started with PIVOT in SharePoint applications. Want to create application similar to http://www.wssdemo.com/SitePages/LiveLabsPivot.aspx Any pointers will be very appreciated. Thanks!

Excel 2003 pivot table - parent showing grand total than the sum of its children

All, In Excel 2003, I have a product hierarchy, for simplistic sake lets say it goes A > B > C > model nbr.  I have filtered on model nbr 1.  I have the product hierarchy in my pivot table and unit cnt as the measure. Starting at level A in the hierarchy I am showing a total unit of 12000, if I drill down to B it still shows 12000, if I drill down to C it shows 100 and if I drill down to model nbr it shows me model nbr 1 with a unit cnt of 100. So my question is why are my parents not filtering the model nbr, it is taking the total for ALL records that have level A as their parent regardless of the model nbr? This does NOT happen in Excel 2007 or when I browse my cube in SSAS.

"Non-additive" target value in KPI. How to present it in a scorecard or Pivot Table.

Hi.. I would like to have some help in designing the following solution. It musn't be to hard, but i can't figure it out yet.. I have 2 tables: Group and Worker. Table Group has GroupID and GroupTarget. Table Worker has WorkerName, GroupID, WorkerTarget and Amount. The relation between tables is GroupID, as each worker belongs to a group. Now I want to take this to a pivotTable, to present KPI for each worker, and the value of the indicator is calculated comparing the Amount vs the WorkerTarget. Also I setup a single hierarchy in the PivotTable, where the parent is the GroupID, and when displayed, you can see all the Workers belonging to that group. Now the problem is, Everything is fine when I want to see the actual group total amount value, as I just have to SUM all the Amounts of each Worker, and I can see the GroupAmount. But.. ¿How can I display the GroupTarget in the PivotTable in the same column as the WorkerTarget? I don't mind a solution using SSAS or PerformancePoint, but my idea is in SSAS to put some kind of formula in the KPI target, so when I'm in a level of the hierarchy, the target is WorkerTarger, and when I'm in the parent, the target is GroupTarget. Is there some kind of formula like this??   If not, any other idea will be much apreciated.. Thanks a lot.. regards.. Canario O.

how to find local time and date usin gmt time and ofset value

Hi All, i have to calculate local time and date in our data base i have gmt time range from 00:00 to 23:59 and offset is in same range but with + an - sign when + then we have to substract and when - then we have add and adjest the date with the given time for eg  gmt id 23:30 and ofset is +2:30 and date is '28-08-2010' then my local time is 23:30 -2:30  =21:00 and date will not change i want a cricteria like when offset get added then value should not be like 22:60 insted of this it is 23:00 and if it is exiding 24 then date should be increase and if time is - after gmt+ofset then date should be redused   Please give me a idea so i can solve it.  

How to change connection string of a pivot table pointing to SSAS 2005 cube using excel 2003?

Hi All,I am not sure if I should have posted this query to Excel 2003 forum. But posting it here as it applies to SSAS 2005 as well.Ok, let me give the background before I tell the actual problem.We have users on ABC domain and the SSAS server is also on ABC domain. Users on this domain can acess the excel pivots by connecting to cube to browse the data. They leave the Userid & password field blank while they setup the connection string and it works fine. Thanks to windows authentication that takes the credentials of user logged in. Let's say I have two users A and B, they login to ABC domain with their own windows ids.  Now when user A creates a excel file having a cube pivot and then sends this file to user B, user B can refresh and modify the same excel file (he can select new measures to pivot, new hierarchies in filters and so on).Now, let's say I have another user, user C. He has excel 2003 installed on his PC and cannot migrate to excel 2007. He is on different domain XYZ but have a valid windows userid on domain ABC. The domain ABC & XYZ can not be setup to have trusted relationship. Now, when user A sends the same excel file to user C. When user C opens the file and try to refresh it or try to modify the pivot by selecting/deselecting any elements, he gets below error prompt:" An error was encountered in the transport layer." and "Errors in the

SQL PIVOT Table to regular sql table.

Hello, I have a fairly complex SP which produce a pivot table with dynamic columns. I was wondering if there is a way to copy that result table to another one with same columns/rows/data, except that the second table is actually stored in the database rather than just produced at runtime. I tried something like: SELECT * FROM (runtime_generated_PIVOT_Table) INTO (new_Table) but that did not work.... (probably didn't work because of the PIVOT table query, not sure)Steve

Create an Excel contraining PIVOT feature in ASP.NET

Hi, We have to generate an excel sheet with pivot table from ASP.NET Web page. Please advice me with some approaches. Thanks in advance. Ratheesh 

Retrieving users from mapping/pivot table

I have three tables.CustomProfileUserID (pk)DisplayNameCompanyIDTeamsTeamRecordID (Pk)TeamIDCompanyIDEmployeesInTeamsUserIDTeamIDI want to assign employees to teams via a gridview control with a templated checkbox.I have a dropdownlist control to select the TeamID.I am having problems with the select statement.The gridview needs to select employees that are not assigned to any teams as well as assigned to other teams. An employee can be assigned to many teams.What I have been trying is:cp.UserID, cp.DisplayName, et.TeamIntID, cp.CompanyID FROM            EmployeesInTeams AS et CROSS JOIN                          CustomProfile AS cp WHERE        (et.TeamIntID <> @TeamIntID) AND (NOT EXISTS                              (SELECT        TeamIntID, UserID                                FROM            EmployeesInTeams                                WHERE        (cp.UserID = UserID))) AND (cp.CompanyID = @companyid)Select cp.UserID, cp.DisplayName, et.TeamIntID, cp.C

Filtering pivot table by KPI value

Hi, All ! I've been faced with following problem. I have a kpi that shows whether the dealer has send report in time. This KPI may return two values 1 - in time, -1 -  not in time. I built a simple pivot table in rows of which are dealer name, in column - KPI and in filter - month name. I'd like  to filter dealers by their status, to see only dealers, who haven't send report in time. I tried to filter in the pivot table by value, but without result. How I can doo it ? I thought may be worth  add a some attribute to dealer dimension that contain a KPI value and filter by this attribute ? Thanks in advance !

Excel pivot table report filter selections from a cube

There are two filters added to the report filter, Date (8/31/2010) and Product (Product A), from a cube I have.  Everything works just fine.  Once the cube is refreshed each day to include the new data, for some reason, only the selection of Date, 8/31/2010, stays but the selection of Product changes to All Products.  Both dimensions are fully processed but the surrogate keys for existing records do not change.  I checked the MDX captured in Profiler and in the where clause, the date selection is passed from the pivot table but the product selection is lost and all products is passed in.  Any thoughts? TIA. 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend