.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

MDX query to only return first row.

Posted By:      Posted Date: September 06, 2010    Points: 0   Category :Sql Server
I have a given MDX query AND would like to only return a single row instead of the full result set. also I need to do this in a way so I can simple add a line to it without re-writting the entire statement. any suggestions how to do this? background: I running stored MDx queries against the cube using OPENQUERY. the result set I parse first to understand what is part of my dimension (not time) and what column defines the time so I can later on work with the results. any hekp is appreciated.

View Complete Post

More Related Resource Links

Check if Linq query return result

HelloI have Linq query likeDim Prood= (From p InProdutcts _                                          where p.ProductID="InputInteger"                                                         ..... ) .SingleOrDefaultI could Use Count if I Use .ToList Instead of .SingleOrDefault , But now that I use 'SingleOrDefault', how Could I find if Prod contains any record or it's Empty.

Return default value from LINK query

I am using the  query listed below which includes multiple joins, in the result of the query I need to do some value replacement values Example: db.ASSETS.BUILDING_ID=300 that ID does not exist in db.BUILDINGS, in that case I need to return BUILDING_ID=0, db.BUILDINGS.NAME="Unassigned" Please help  var productQuery = from assets in db.ASSETs join relocatableUnits in db.UNITs on assets.UID equals Units.RUID into assets_units from Units in assets_units.DefaultIfEmpty() join build in db.BUILDINGs on assets.BUILDING_ID equals build.BUILDING_ID into assets_bins from build in assets_bins.DefaultIfEmpty() join test in db.TEST_SUITEs on assets.TEST_SUITE_ID equals test.TEST_SUITE_ID into test_bins from test in test_bins.DefaultIfEmpty() join testTrgt in db.TEST_SUITEs on assets.T_TEST_SUITE_ID equals testTrgt.T_SUITE_ID into testTrgt_bins from testTrgt in testTrgt_bins.DefaultIfEmpty()

Return linq query in function

I try to return a var query from a function, but i'll get the error: Error:Error 41 Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<AnonymousType#1>' to 'System.Collections.Generic.IEnumerable<System.Xml.XmlElement>'. An explicit conversion exists (are you missing a cast?)  Code: protected static IEnumerable<XmlElement> GetModels(byte MerkID) { string rawXML = AutoDisk.GetModels(12345, true, MerkID, "2010", ""); XmlDocument xml = new XmlDocument(); xml.LoadXml(rawXML); var query = from feed in xml.DocumentElement.ChildNodes.Cast<XmlNode>() select new { nModelID = feed.SelectSingleNode("nModelID").InnerText, Modelnaam = feed.SelectSingleNode("Modelnaam").InnerText }; return query; } Whats wrong and how can i make this working ?  

Query to return TOP n with 'Other' grouping for all remaining rows

Hi all, I've been given a specific type of report to produce, and am having difficulty in getting my SQL right to return the data as needed. I need to return TOP n Categories based on amount of sales (which I can do) but then a final category with a sum of all other sales. The purpose would be to capture all of the small sales values into one 'Other' category so that the chart I'll produce does not have lots and lots of small-value columns. I found the following post which seems to come close: SELECT TOP 10 CompanyID, CompanyName, SUM(GrossSales) [GrossSales] FROM CompanySales GROUP BY CompanyID, CompanyName ORDER BY SUM(GrossSales) desc UNION SELECT -1, 'Other' [CompanyName], SUM(GrossSales) [GrossSales] FROM CompanySales WHERE CompanyID NOT IN ( SELECT TOP 10 CompanyID, CompanyName, SUM(GrossSales) [GrossSales] FROM CompanySales GROUP BY CompanyID, CompanyName ORDER BY SUM(GrossSales) desc ) But this gives a syntax error on UNION, which I'm guessing is due to the ORDER BY clauses. However I think the ORDER BY is needed to ensure I return the results in the correct order. Does anyone have any ideas of how to do this? Thanks for any assistance Matt

how to query return all data in Array Object ,Collection Object

how to query return all data in Array Object ,Hash Table ,And DataTable dataRowSelect * From Doc a

function or query to return continuous span of months $ years as rows in query



I am using SS2008.

There are many situations in which I need to return a table where the rows are EVERY calendar month between two dates, not just the months where there is data present.

Is there a function that would take a beginning and end date mmddyyyy which would do this?

For example if I wanted 1/2004 through 8/2010?




and so on to





Thanks in advance,




One to many query: return most common value


I am working on a one to many query for an assets database.  Here is some sample data

Server Name        Application        Primary_User
Server1                 SQL                   DBA
Server1                 Citrix                 IT
Server1                 Oracle                DBA
Server2                 Sharepoint         Web
Server3                 SQL                   DBA
Server3                 Sharepoint         Web
Server3                 Norton               Security
Server3                 IDS                   Security

The desired output is one row per server with the server name, count of applications, and the Primary User that appears the most (not just the first, last, min, or max).

It would look like this

Server Name    Applications  Primary_User
Server1            3                  DBA
Server2            1                  Web
Server3            4                  Security

Is there a sub query that can accomplish this?  Thanks in advance!

Using SQL to return matches from 2 different bits of data in one query


Hi there,

i am writing a website that has a social networking element to it, and i want to display mutual friends of the person being viewed with the person that is viewing.

is it possible to search one database table and look for matching entries using 2 different usernames? if so how would i do it?

hope u can help,

many thanks

Query to return conditional counts both distinct and non distinct.


I have the following table structure:

Table EmailTracking



Table EmailTrackingDetail


The following query returns the default recordset:


SELECT     TOP (200) EmailTracking.EmailAddress, EmailTrackingDetail.TranType, EmailTrackingDetail.TranDate
FROM         EmailTracking INNER JOIN
                      EmailTrackingDetail ON EmailTracking.RecordID = EmailTrackingDetail.EmailTrackingRecordID







2010-09-21 16:59:29.980



2010-09-21 17:19:58.790



2010-09-27 12:00:30.940

different results return from .NET and sql query analyzer



Below is my code how to get the records from a stored procedure. I can get the correct results from sql query analyzer, but less results in .NET. Why it happened? How to solve it? Thank.

strSQL = "EXECUTE sp_Collection '" & strRECID &"','" & strPayPeriodFrom & "','" & strPayPeriodTo & "','" & intPayDays & "' "

objDB = DatabaseFactory.CreateDatabase()
            objDS = objDB.ExecuteDataSet(CommandType.Text, strSQL)

objDB = DatabaseFactory.CreateDatabase()

 objDS = objDB.ExecuteDataSet(CommandType.Text, strSQL)

*NOTE: connected to correct database

Query to Return Rolling 12 Month Totals



I have a table that looks like this:

[Date], [Person], [Value]

22/03/2008, Person A, 3.1

22/03/2008, Person B, 4.2

03/04/2008, Person B, 5.1

04/04/2008, Person B, 3.0

06/04/2008, Person C, 3.0

I need a query to return a table that shows the totals of each person's value for each month of the proceding 12 months from Date X.  So if Date X is 30/04/2008 then my result table would look like this:

[Month], [Total]

March, 7.3

April, 11.1

Thanks in advance.





select query doesnt return values


hi all, i need your assistance please.


select Comments.Id,SuroundId,ArticleId,PosterId,PostRime,Subject,Body,Visible,Users.Username
from dbo.Comments
inner join Users on Comments.PosterId=Users.Id
where SuroundId=@suround and ArticleId=@articleId

for some reason it doesnt return any values.

before i've added the inner join it worked perfectly.

i couldn't find my mistake, though i passed over it several times.



Webmatrix.Data.Database.Query() method return type


I'm using the Webmatrix.Data.Database.Query method to return a result set in the following form

var myResult = db.Query("Select * from mytable");

How do you cast myResult to get the count of records returned? I'd like to do something like


Search is currently configured not to return more than 50 results for any query. You asked for resul


Hi All,


I was working on MOSS 2007 OOTB search no customisation.

Customisation of look and feel using XSLT.

My issue is i need to show only top 5o records on searchresults page each page should contain 10 items, i configured according to that in search core results webpart properties, but if i go to 5th page it is showing "next page" symbol if i click on it shows an error message:

"Search is currently configured not to return more than 50 results for any query. You asked for results starting from 51"

I shouldnt show next symbol @ 5th page ...how can i overcome this issue.



MS SQL Server: Search All Tables, Columns & Rows For Data or Keyword Query

If you need to search your entire database for specific data, this query will come in handy.

So when a client needs a custom report or some sort of custom development using Great Plains, most of the time I will have to track down the data in the system by running this query and find the table(s) it is in.

How to Encrypt Query String Parameters in ASP.NET

Encrypt Query String Parameters in ASP.NET.u can send secure data one page another page u can also use query string to encrypt

Content Query Web Part missing in SharePoint 2010

If you don't see content query web part listed in the web parts list, this is because you have not enabled "Search Server Web Parts" feature in site collection features. Enable this feature and content query web part will show in the list of web parts.
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