.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

Pivot w/o aggregation...query not working

Posted By:      Posted Date: August 28, 2010    Points: 0   Category :Sql Server
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!

View Complete Post

More Related Resource Links

Caml query not working

Hi, I'm trying to query a SPListItem from a sharepoint list but it doesn't seem to work:   SPDocumentLibrary myDocuments = (SPDocumentLibrary)site.Lists["Documents"]; SPQuery query = new SPQuery() { Query = " <Where>" + " <Eq>" + " <FieldRef Name='DocumentPath' />" + " <Value Type='Text'>" + source + "</Value>" + " </Eq>" + " </Where>" }; var result = myDocuments.GetItems(query); I get no result, but there's an item with the specified "source" that does exist.

Why is the Content by Query Web Part CommonViewFields attribute not working as expected?

I am using the Content by Query Web Part to show data from a Custom List.  I have already added to the XSL "ItemStyle" sheet so that I can pick the correct Item Style.  That has worked fine - I have been able to show whatever fields I would like and apply any CSS Styles I would like to them.  The issue I am having is in formatting the field correctly.  I have two different fields in my current example that need to be formatted: [1] I want to show an Image, but right now it shows the URL  [2] I want to show Rich Text, but right now it shows all the HTML Code as Plain Text.  I have looked at many articles online, and they all tell me to change the following in the WEBPART file from: <property name="CommonViewFields" type="string" /> to: <property name="CommonViewFields" type="string">Thumbnail, Image;Teaser, RichHTML;</property> What I am doing wrong?  The Web Part still runs, but it does not format the fields any differently.  Thanks for the help!

CAML query on external list is not working

Hi, I have an external list, display data from SQLServer 2008. Table on SQL have an UniqueIdentifire (GUID) type column as a Primary key. It also has one identifier column, Its value is increased by 1, as the item is created. In share point server side code, I want to fetch single record against the primary key GUID value. I write down the CAML query on GUID column and run without any error. But all the external list data is returned instead of Single list item. I also try to filter on Auto Incremented column, but same problem is occurred.

query with locks not working in sql server 2008

I have a select query with join on some view and locks as (readpas,updlock) after executiong this query it executes the same query with little modification( no locks etc). This sequence of query executes fine in SQL server 2000/2005.   When I am executing same seq in sql server 2008 through application, I am getting timeout for second query. Can someone please suggest what can be the reason? I cannot post the query.Cheers!!! Vatsa

Pivot table query dynamic column.


Hello All,


I want to export my data to excel sheet. The logic to export data in excel is clear.

Now my query is I have 3 tables and I want to generate the data jst like below.



Company Name

Company Email


Create Date


Fax No














And so on.....


The data will come from 3 tables I.e


  1. Master Table for Company

  2. Converting an Access pivot query to SQL 2005


    Hi, I am new to table pivot and would like to know how to go about converting the following query in Access to SQL Server 2005:


    SELECT tbl_Proj_Budget.PROJ_ID,
    FROM tbl_Proj_Budget 
    GROUP BY tbl_Proj_Budget.PROJ_ID 

    1) what does the 1st line mean?


    2) How would I conver this to TSQL ?




problems in pivot query




             I am using following pivot query  but not getting result as single row getting as 4 rows.

One more problem i am unable to pass dates as parameters to storeprocedure something like this

select [@date] .

        SELECT 'Forecasted' AS HeadCount,
[8/1/2010], [8/8/2010], [8/15/2010], [8/22/2010]
FROM TblEmpCount) AS SourceTable
FOR StartDate IN ([8/1/2010], [8/8/2010], [8/15/2010], [8/22/2010])
) AS PivotTable;

I am getting result as 4 rows but i want result in single row like this

HeadCount    8/1/2010     8/8/2010    8/15/2010    8/222/2010

Forecasted     191                182                 176                169





Help figure out where records are being dropped from a pivot query


I have a stored procedure that creates a pivot query. The problem I'm having is that the inner query is returning 1641 records, then when the pivot is executed, only 1450 records make it to the result set.

The query is as follows:

SELECT CallSegments.AppName, CH.CallDate, dbo.fn_IsContacted(CH.AppName, CH.Result) AS Contacted, CallSegments.QueueID, dbo.fn_GetResultCategory( CallSegments.AppName, CH.Result ) AS CallResult 
FROM CallSegments, CallHistory AS CH WHERE CH.CallInstance = CallSegments.CallInstance 
AND RTRIM( CallSegments.AgentID ) = '' 
AND RTRIM( CallSegments.QueueID ) <> '' 
AND CH.AppName = 'some_client' 
AND CH.CallDate >= '11/3/2009 00:00:00.000' AND CH.CallDate <= '11/3/2009 23:59:59.997' 


The interesting thing, for me, is that I can copy the internal select clause and run it separately. When it executes, I receive 1641 records in the result. Then when it goes throug the pivot, records are dropped. I don't quite understand because all of the inner records have a category listed in the pivot list. I've looked it over several times but I just can't see where I'm losing records.

sql select query not working


hi guys,

i have been having trouble trying to find out what is wrong with my sql select query... i wanted to select a sessionID by comparing the tourID and dates. the dates datatype at the database is datetime and the value of itemSessionDate is in string. i tried to convert itemSessionDate to date and dateAndTime but it gave me mm/dd/yyyy while the date in my database is dd/mm/yyyy hh:mm:ss. so i thought i can try using the itemSessionDate string as it has the same value as the one return from the database. but it keeps on goin to the if not reader.hasRows and quit the statement

could somebody teach me how to solve this problem....

below are my code

Private Function getItemSessionID(ByVal tourID As String, ByVal itemSessionDate As String)
        Dim sessionID As String = ""

        Dim strConn As String = ConfigurationManager.ConnectionStrings("ProrsumDBConnectionString").ConnectionString
        'create sql connection
        Dim myConn As New SqlConnection(strConn)
        'Open connection; Note: You need to open a connection to database

            Dim cmd As String = "SELECT sessionID " & _
                                " FROM TourSession " & _
                                " WHERE tourID=" & Integer.Pars

Use power pivot to query the data in MS CRM


Hi All,

I want to query the data in MS CRM (entities) using power pivot from IT Share Point. Can any one guide me in this please.


Trouble working examples of Cumulative columns in SQL Query


I can run the following query without the built in query in the select statement and it works fine.  All i am trying to do is to create a cumulative total for each day for a specific date range.  Any ideas?


SELECT OrderHed.OrderDate,

     (SELECT SUM(OD.OrderQty * OD.ListPrice)

        FROM   MFGSYS.PUB.OrderDtl OD INNER JOIN MFGSYS.PUB.OrderHed OH ON (OD.Company=OH.Company) AND (OD.OrderNum=OH.OrderNum)

        WHERE OH.orderdate<=OrderHed.OrderDate)

 FROM   MFGSYS.PUB.OrderDtl OrderDtl INNER JOIN MFGSYS.PUB.OrderHed OrderHed ON (OrderDtl.Company=OrderHed.Company)

    AND (OrderDtl.OrderNum=OrderHed.OrderNum)

 WHERE  (OrderHed.OrderDate>={d '2010-10-01'}

    AND OrderHed.OrderDate<={d '2010-10-31'})

    AND OrderDtl.Company='HEAPG'

    AND OrderDtl.RMANum<1

 GROUP BY OrderHed.OrderDate

 ORDER BY OrderHed.OrderDate

Query not working


I am getting this error message

The name 'factoryQuery' does not exist in the current context

To see if the IF worked I put in a response. redirect and that worked but it says the factoryQuery is not found

no idea why it won't work .

Here is the code


if (Convert.ToInt32(Session["UserAccType"]) < 4)
  //  Response.Redirect("nn.aspx");
   string factoryQuery = " SELECT complete, Count(*) as TotQ  FROM recommendations INNER JOIN inspection ON recommendations.InspectionID = inspection.InspectionID INNER JOIN location ON inspection.LocationID = location.LocationID INNER JOIN UserLocations ON UserLocations.LocationID = location.LocationID WHERE (([Userlocations].[UserID] = @UserID))GROUP BY Complete";
    string factoryQuery = " SELECT complete, Count(*) as TotQ FROM recommendations GROUP BY Complete";

        DbConn oRs = new DbConn(factoryQuery);

        //Iterate through each record

SP Datasource select Command not working for Status Column



    (MOSS 2007-Webuser control Web part)

    I'm having a cutom list that i'm binding using SPDatasource to a gridview. I want to filter the list based on column values. I tried the following code

            SPList taskList = site.Lists["Accounts"];
            SPDataSource mySPDS = new SPDataSource();

         mySPDS.SelectCommand = "<View><Query><Where><Eq><FieldRef Name='Vendor_x0020_Name'/><Value Type='Text'>"+ddlVendorName.SelectedItem.Text +"</Value></Eq></Where></Query></View>";


mySPDS.SelectCommand = "<View><Query><Where><Eq><FieldRef Name='Status'/><Value Type='Choice'>" + ddlStatus.SelectedItem.Text + "</Value></Eq></Where></Query></Vi

LDAP Query is not working


Hi All,


we are using SharePoint 2007.


We are facing a peculiar problem and need your help/ suggestions:


Problem Statement: The Intranet is importing user profiles based on a ldap query and user filter defined in central admin. The user filter selectively rejects “not active” profiles and profiles that belong to a user group: NonIT_Staff (this group is used to store profiles who have left organization or some selected admin accounts)


The user filter used is: (&(objectCategory=person)(

Query issue - Pivot?


I a query that returns the following:

Day    TypeID     Product A     Product B
1        1            10               20 
1        2            30               40
2        1            50               60 
2        2            70               80

But, i need to return the following:
Day    Product A Type1     Product A Type2     Product B Type1
     Product B Type2
1       10                        30                        20                        40

Users use Excel-Pivot table to query the cube, how to capture those queries?


Most of our users use Excel'10 for querying the cube,

I've set up the querylog-properties in SSAS engine but it only captures the query from SSAS engine and not from the other platform such as Excel. So, when I use Usage based aggregation wizard, it shows the users/ueries from SSAS engine only. Is there any way to capture the user/query information that comes through Excel pivot table and somehow create aggregation through that information?


Any suggestion/help is very much appreciated,


Working with SharePoint document libraries

Document libraries are collections of files that you can share with team members on a Web based on Microsoft Windows SharePoint Services. For example, you can create a library of common documents for a project, and team members can use their Web browsers to find the files, read them, and make comments. Users with Microsoft Office 2003 can check out and edit the files as if they resided on a local or network drive.

By default, your team Web site comes with a built-in document library named Shared Documents, which is listed on the Quick Launch bar as well as on the Documents and Lists page.
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