Showing posts with label exists. Show all posts
Showing posts with label exists. Show all posts

Sunday, March 25, 2012

(Newbie) Trying to get rid of NonEmptyCrossJoin

Hi everyone,

As I have said before, I am new to MDX. Any help much appreciated.

I am trying to substitute the Exists() function for the NonEmptyCrossJoin() function, but Exists is not producing the results that I would expect. The test query that I am running is:

SELECT {[Measures].[Value]} ON COLUMNS,

NonEmpty({[Fact].[Name].[All].CHILDREN}) ON ROWS

FROM [AS Test1]

WHERE

NonEmptyCrossJoin({[Start Date].[Month Hierarchy].[2006-01-01 00:00:00]:[Start Date].[Month Hierarchy].[2006-06-02 00:00:00]},

{[End Date].[Month Hierarchy].[2006-06-15 00:00:00]:[End Date].[Month Hierarchy].[2006-12-31 00:00:00]})

This is not ideal code, but performs correctly, only listing members with start and end dates with the appropriate values. I tried to substitute that query for this:

SELECT {[Measures].[Value]} ON COLUMNS,

NonEmpty({[Fact].[Name].[All].CHILDREN}) ON ROWS

FROM [AS Test1]

WHERE

Exists(NonEmpty({[Start Date].[Month Hierarchy].[2006-01-01 00:00:00]:[Start Date].[Month Hierarchy].[2006-06-02 00:00:00]}),

NonEmpty({[End Date].[Month Hierarchy].[2006-06-15 00:00:00]:[End Date].[Month Hierarchy].[2006-12-31 00:00:00]}))

This query effectively ignores the second set (i.e. the End Date set), listing all values with start dates in the given range. Can anyone tell me what I am doing wrong?

Any help much appreciated.

Edit: Adding a measure group at the end of the Exists function and/or removing the NonEmpty functions do not correct the problem.

Not sure whether you've read this blog entry, which discusses different scenarios in which NECJ was used. The closest equivalent is Exists() with measure group, but it depends on the scenario in which NECJ was being used:

http://sqljunkies.com/WebLog/mosha/archive/2006/10/09/nonempty_exists_necj.aspx

>>

MDX: NonEmpty, Exists and evil NonEmptyCrossJoin

...

NonEmptyCrossJoin(set1, set2, ..., setN, K) is equivalent to Exists(set1*...*setK, set(K+1)*...*setN, "measuregroupname")

where "measuregroupname" is the name of the measure group to which the current measure belongs.

...

>>

So, in your case, it should be like:

Exists({[Start Date].[Month Hierarchy].[2006-01-01 00:00:00]:[Start Date].[Month Hierarchy].[2006-06-02 00:00:00]}

* {[End Date].[Month Hierarchy].[2006-06-15 00:00:00]:[End Date].[Month Hierarchy].[2006-12-31 00:00:00]},, "measuregroupname")

|||

Hi Ed,

First of all, why are you trying to replace NECJ with Exists rather than NonEmpty - are you setting the NullProcessing property anywhere? I think you're better off using the NonEmpty function here.

Secondly, in my experience you should always include a measure somewhere in either of the sets you pass into NonEmpty - especially if you have multiple measure groups in your cube. If you don't then I think what happens is that you remove all the items in your set which are empty for all measures in the cube, which can be confusing when you're only showing one measure and can also slow your query down.

So... does the following do what you want?

SELECT {[Measures].[Value]} ON COLUMNS,

NonEmpty({[Fact].[Name].[All].CHILDREN},[Measures].[Value]) ON ROWS

FROM [AS Test1]

WHERE

(NonEmpty({[Start Date].[Month Hierarchy].[2006-01-01 00:00:00]:[Start Date].[Month Hierarchy].[2006-06-02 00:00:00]} *

{[End Date].[Month Hierarchy].[2006-06-15 00:00:00]:[End Date].[Month Hierarchy].[2006-12-31 00:00:00]},[Measures].[Value]))

HTH,

Chris

|||Thank you very much Chris and Deepak for your replies. I'll give those approaches a try.

Thursday, March 22, 2012

(Default) instance already exists (not really!)

Ok,

I haven't had this much trouble installing MS software in many moons. My end goal is to install Team Foundation Server, but to do that I need SQL Server 2005 first, then SharePoint, then TFS. At each of these steps it is appearing to be a mine field, and it is apparent that the MS Installer is doing a terrible job at uninstalling everything.

End of whine. So my situation is this, I had installed MS SQL Server Developer 2005 and found out that the Reporting Server wasn't working. Basically, because at one time or another I had FP extentions installed, and permissions were hopelessly munged. The fix on the forums was to back everything out... SQL Server, IIS, Sharepoint, and do a scorch and burn, effectively erradicating any trace that any of these existed on the disk.

This accomplished, but... now when I try to reinstall SQL Server, it claims the default instance "already exists." So... I've tried various registry hacks, tracking down any trance of instances. Here are some of things I've tried to no avail...

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=148487&SiteID=1
http://support.microsoft.com/default.aspx?scid=kb;en-us;290991&sd=tech
http://support.microsoft.com/default.aspx?scid=kb;en-us;290301

So... short of going beyond scorch and burn, and nuke the entire machine, what are my options? Erasing the OS and starting from scratch does not seem like an option because, it seems, that seems I'll never get anything installed if I have to keep doing this.

Ideas anyone? Your help is greatly appreciated.

-Eric

FYI -- When running RegSeeker I find nearly 300 bogus registry entries left over from the MS uninstall--someone's got to fix that.Ok, I found a possible solution. But... it is very very risky. So don't blame me if you torpedo your server using my advice. But it worked for me.

But I'm posting this in case someone else find themselves in the same bind as me.

Following the suggestion of one of the other forum posts I saw, I looked for all entries for SQL Server. I saw a zillion entries for version 9.0.242.0.

Using RegSeeker, I wacked those. So they were gone.

Next, I saw another bazillion entries for "SQL Server." I surmized that SQL Server was completely uninstalled, these should be gone as well. So I delete those as well.

Another search for "SQLServer" also turned up a bazillion entries. Most of these were classes. Taking a deep breath, I deleted all of these as well.

In all, there were many thousands of registry entries that probably should have been deleted by the uninstall, but weren't.

So far, I've managed to reinstall SQL Server 2005 Developer and all is A-OK. So problem solved (I'd knock on wood if I have any real wood in my cube).

-Ericsql

Sunday, March 11, 2012

"NOT IN" SQL Statement

Hi,

I need to create a SQL statement as a datasource. I need the SQL statement to exclude the records that exists in another table!

I tried to use the where clause

SELECT X.A,X.B,X.C,X.D From X

where X.B,X.C,X.D NOT IN (

SELECT Y.E,Y.F,Y.G

From Y

)

The SQL Statement works fine when I have only one column in the NOT IN part but gives me syntax error when I have more than one column in the NOT IN part.

Please advise how can I write this SQL statement in T-SQL

Thanks,

Aref

select a, b, c, d, e, f

from table1 as t1

where not exists(select * from table2 as t2 where t2.a = t1.a and t2.b = t1.b and t2.c = t1.c)

|||For more information about the provided syntax by joeydj look for the keyword correlated subqueries.

HTH, Jens SUessmeyer.

http://www.sqlserver2005.de

"No data exists for the row/column" (InvalidOperationException) after a number of read

I've been looking around for some kind of known issue or something, but can't find anything. Here's what I'm experiencing:

I have a table with about 50,000 rows. I open several connections and use a command to ExecuteResultSet against each command, with CommandType.TableDirect, CommandText set to the name of the table, and IndexName set to various indexes. In the end, I have several SqlCeResultSet instances which are then maintained for the life of the AppDomain.

In a loop, I call SqlCeResultSet.Read() on one of the instances, and if it returns false, I call SqlCeResultSet.ReadFirst() - essentially creating a circular pass through the result set.

In a Visual Studio debug session, this approach goes swimmingly for a short time, and then after a successful Read(), I'm pegged with an InvalidOperationException (text: "No data exists for the row/column") for a column which was succesfully read on the previous Read(). If, in the immediate window, I call SqlCeResultSet.Read() again on the result set instance, the Get methods work as they had been in the previous reads.

It seems like the internal state of the ResultSet is getting corrupted somehow, but it is opaque to me. Any insights on why this suddenly throws this exception?

Well, the way around this, apparently, is to keep trying the operation until it succeeds. I have a governer on this repetition, and I've never had a problem with setting it to 5 - so it apparently succeeds after 5 or fewer retries, at least in my testing

|||

I got this error when I was using the SqlCeResultSet.Seek().
Use a breakpoint on this method to see what happens internally to the SqlCeResultSet
The values are restored once a read() is done, but after the seek and before the read is performed, the fields are unintelligible.
In other words a SqlCeResultSet.Seek() should always be followed up by a read of some kind.

"No data exists for the row/column" (InvalidOperationException) after a number of read

I've been looking around for some kind of known issue or something, but can't find anything. Here's what I'm experiencing:

I have a table with about 50,000 rows. I open several connections and use a command to ExecuteResultSet against each command, with CommandType.TableDirect, CommandText set to the name of the table, and IndexName set to various indexes. In the end, I have several SqlCeResultSet instances which are then maintained for the life of the AppDomain.

In a loop, I call SqlCeResultSet.Read() on one of the instances, and if it returns false, I call SqlCeResultSet.ReadFirst() - essentially creating a circular pass through the result set.

In a Visual Studio debug session, this approach goes swimmingly for a short time, and then after a successful Read(), I'm pegged with an InvalidOperationException (text: "No data exists for the row/column") for a column which was succesfully read on the previous Read(). If, in the immediate window, I call SqlCeResultSet.Read() again on the result set instance, the Get methods work as they had been in the previous reads.

It seems like the internal state of the ResultSet is getting corrupted somehow, but it is opaque to me. Any insights on why this suddenly throws this exception?

Well, the way around this, apparently, is to keep trying the operation until it succeeds. I have a governer on this repetition, and I've never had a problem with setting it to 5 - so it apparently succeeds after 5 or fewer retries, at least in my testing

|||

I got this error when I was using the SqlCeResultSet.Seek().
Use a breakpoint on this method to see what happens internally to the SqlCeResultSet
The values are restored once a read() is done, but after the seek and before the read is performed, the fields are unintelligible.
In other words a SqlCeResultSet.Seek() should always be followed up by a read of some kind.

"No data exists for the row/column" (InvalidOperationException) after a number of

I've been looking around for some kind of known issue or something, but can't find anything. Here's what I'm experiencing:

I have a table with about 50,000 rows. I open several connections and use a command to ExecuteResultSet against each command, with CommandType.TableDirect, CommandText set to the name of the table, and IndexName set to various indexes. In the end, I have several SqlCeResultSet instances which are then maintained for the life of the AppDomain.

In a loop, I call SqlCeResultSet.Read() on one of the instances, and if it returns false, I call SqlCeResultSet.ReadFirst() - essentially creating a circular pass through the result set.

In a Visual Studio debug session, this approach goes swimmingly for a short time, and then after a successful Read(), I'm pegged with an InvalidOperationException (text: "No data exists for the row/column") for a column which was succesfully read on the previous Read(). If, in the immediate window, I call SqlCeResultSet.Read() again on the result set instance, the Get methods work as they had been in the previous reads.

It seems like the internal state of the ResultSet is getting corrupted somehow, but it is opaque to me. Any insights on why this suddenly throws this exception?

Well, the way around this, apparently, is to keep trying the operation until it succeeds. I have a governer on this repetition, and I've never had a problem with setting it to 5 - so it apparently succeeds after 5 or fewer retries, at least in my testing

|||

I got this error when I was using the SqlCeResultSet.Seek().
Use a breakpoint on this method to see what happens internally to the SqlCeResultSet
The values are restored once a read() is done, but after the seek and before the read is performed, the fields are unintelligible.
In other words a SqlCeResultSet.Seek() should always be followed up by a read of some kind.

Saturday, February 11, 2012

#temp table - Checking if it exists

Hi,
I'd like to check if a #temp table I created in a previous session still
resides on the DB.
I've used the following code and have had no luck
*************
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[#temp]')
)
drop table #tempTry:
IF OBJECT_ID('tempdb..#temp') IS NOT NULL
DROP TABLE #temp
Hope this helps.
Dan Guzman
SQL Server MVP
"Jacques Victor" <jacques@.ideosphere.co.za> wrote in message
news:%23I0cQMOOEHA.1616@.TK2MSFTNGP12.phx.gbl...
> Hi,
> I'd like to check if a #temp table I created in a previous session still
> resides on the DB.
> I've used the following code and have had no luck
> *************
> IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[#temp]
'))
> drop table #temp
>

#temp table - Checking if it exists

Hi,
I'd like to check if a #temp table I created in a previous session still
resides on the DB.
I've used the following code and have had no luck
*************
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[#temp]'))
drop table #tempTry:
IF OBJECT_ID('tempdb..#temp') IS NOT NULL
DROP TABLE #temp
--
Hope this helps.
Dan Guzman
SQL Server MVP
"Jacques Victor" <jacques@.ideosphere.co.za> wrote in message
news:%23I0cQMOOEHA.1616@.TK2MSFTNGP12.phx.gbl...
> Hi,
> I'd like to check if a #temp table I created in a previous session still
> resides on the DB.
> I've used the following code and have had no luck
> *************
> IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[#temp]'))
> drop table #temp
>

#temp table - Checking if it exists

Hi,
I'd like to check if a #temp table I created in a previous session still
resides on the DB.
I've used the following code and have had no luck
*************
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[#temp]'))
drop table #temp
Try:
IF OBJECT_ID('tempdb..#temp') IS NOT NULL
DROP TABLE #temp
Hope this helps.
Dan Guzman
SQL Server MVP
"Jacques Victor" <jacques@.ideosphere.co.za> wrote in message
news:%23I0cQMOOEHA.1616@.TK2MSFTNGP12.phx.gbl...
> Hi,
> I'd like to check if a #temp table I created in a previous session still
> resides on the DB.
> I've used the following code and have had no luck
> *************
> IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[#temp]'))
> drop table #temp
>

Thursday, February 9, 2012

##temp table already exists problem

Hello

I am using a temp table called ##temp in an SProc but often get the
message that the table already exists. Could this be because the SProc
is being run by more than 2 webpages at the same time?
Or is it because the sProc has an error and is not getting to the drop
table line?

I have tried adding a line to test if the object exists and to drop the
table before I create it. If I drop it will it affect another instance
of the sProc that is using the same table name?

If so is there a way around this?

Many thanks
NigelGlobal temp tables are visible to all connections, so if you have
multiple processes, then you can easily get errors like that. And if
you drop the table explicitly, one connection could drop the table
which was created by another connection.

Is there some specific reason why you can't use a local temp table? Or
perhaps you can use a permanent table, with @.@.SPID as part of the key?
If you can explain some more about what you're trying to do, then
someone may be able to suggest an alternative solution.

Simon|||Thanks Simon.
So If I use # instead of ## the table is connection based rather than
global. Id did sort of know that but you have made it clear. I will
change to # instead of ##.

The situation is that I have a website that runs an SProc to get the
content of a banner. This runs for most pages on the site.
nigel