Showing posts with label existing. Show all posts
Showing posts with label existing. Show all posts

Sunday, March 25, 2012

(MDX) EXISTING operator - inconsistent behaviour when using subcubes?

I am getting what I think is inconsistent behaviour when using the EXISTING operator to obtain a set defined by the current query context... See the two queries below (explanation follows).

WITH MEMBER [Measures].[MyDate] AS

Tail(EXISTING [Date].[Calendar].[Date], 1).item(0).membervalue

SELECT {[Measures].[MyDate]} ON 0

FROM [Adventure Works]

WHERE [Date].[Date].[October 26, 2002]

... returns [26-10-2002]

WITH MEMBER [Measures].[MyDate] AS

Tail(EXISTING [Date].[Calendar].[Date], 1).item(0).membervalue

SELECT {[Measures].[MyDate]} ON 0

FROM

(

SELECT [Date].[Date].[October 26, 2002] ON 0

FROM [Adventure Works]

)

... return [31-08-2004] (the last date in the Adventure Works time dimension).

From my point of view the two queries should return the same date (October 26, 2002), since the context is the same. The only difference is that in the first query the context is specified in the WHERE clause, whereas the second query specifies the context in a subcube. There really should not be any difference, should there?

I agree this looks confusing but I suspect it's intended functionality: calculated members can 'look outside' a subcube defined in the FROM clause (see http://spaces.msn.com/cwebbbi/blog/cns!7B84B0F2C239489A!212.entry for example). This would be useful, for example, if you had a previous period growth calculation that you wanted to return a meaningful value even when you were querying a subcube which had been restricted to just one Date.|||

Chris, I was looking for an answer from you - not quite the answer I hoped for though.

I see your point, but if what you are saying is true, the value of the EXISTING operator is not very high and it will be very questionable if Moshas approach to writing "multiselect friendly MDX calculations" (http://www.sqljunkies.com/WebLog/mosha/archive/2005/11/18/multiselect_friendly_mdx.aspx) is applicable (which I really hope it is!). Does it not also fail to explain why the following query only returns the sum of [Internet Sales Amount] from 2002 and 2003 (which - to me - is expected behavior)?

WITH MEMBER [Measures].[Test 2] AS

SUM(EXISTING [Date].[Date], [Measures].[Internet Sales Amount])

SELECT [Measures].[Test 2] ON 0

FROM

(SELECT {[Date].[Calendar Year].&[2002], [Date].[Calendar Year].&[2003]} ON 0 FROM [Adventure Works])

If what you are saying is true, wouldn't the calculated member return a sum for all years - since the calculated member would "look outside" the subsube, which is restricted to 2002 and 2003?

|||

I think you've made a mistake in your query - the expression [Date].[Date] resolves to the All Member of that hierarchy. I think what you wanted to do was this:

WITH MEMBER [Measures].[Test 2] AS

SUM(EXISTING [Date].[Date].[Date].Members, [Measures].[Internet Sales Amount])

SELECT [Measures].[Test 2] ON 0

FROM

(SELECT {[Date].[Calendar Year].&[2002], [Date].[Calendar Year].&[2003]} ON 0 FROM [Adventure Works])

Which returns a different (and higher) value, the sum of all years.

You're right, though, it does cause problems if you're using subcubes instead of sets in the where clause and following Mosha's advice on multi-select friendly MDX.

Chris

|||You're right Chris - thanks... I will try go get Mosha to comment on this issue... I will follow up in this thread.|||

I know this was an area where there was some discussion about what the most useful behaviour would be - on balance, I think they've done the right thing. As far as the multi-select issue goes, is there any reason why you're not using sets in the WHERE clause instead?

<Cheeky Plug>
This topic is discussed in the second edition of 'MDX Solutions' in one of George's chapters:
http://www.amazon.co.uk/exec/obidos/redirect?link_code=ur2&tag=chriswebbsbib-21&camp=1634&creative=6738&path=ASIN%2F0471748080%2Fqid%3D1141661836%2Fsr%3D8-3%2Fref%3Dsr_8_xs_ap_i3_xgl
</Cheeky Plug>

Chris

|||

Just placed an order for this book yesterday, so I am looking forward to reading the good arguments for the current behavior.

Why am I not using sets in the where clause for multi-select? There are more than one reason actually.

1) If a hierarchy is placed in the WHERE clause, the same hierarchy cannot - as you know - be placed on an axis (which, in many cases, in desireable).

2) The use of the WHERE clause vs. the use of subcubes for restricting the query result varies from client tool to client tool. The cube browser in SSMS, for example, uses both subcubes and sets in the WHERE clause depending on how you setup the query.

One could argue - perhaps - that the client tool should be smart enough to always place any hierarchy not already on an axis in the WHERE clause?! I wonder if this would always solve any problem? Hmm...

|||

EXISTING operator takes into account current coordinate. The whole difference between WHERE clause and subselect, is that WHERE clause sets current coordinate, while subselects merely do top level Exists with Axis (BTW WHERE clause also does it), and apply visual totals.

The confusion between WHERE and subselects is big and seem to grow every day :( It is unfortunate that not everybody realizes the semantic difference between the two and when each should be used. Perhaps we need another operator in MDX which will take into account the current restriction of subselect and/or CREATE subcube. Excel 12 is only going to add to the confusion, since it uses subselects extensively and it uses them for multiselect too, rendering my advice on how to write multiselect friendly calculations less useful...

Mosha

|||

I blogged on this topic.

http://sqljunkies.com/WebLog/reckless/archive/2006/03/08/18601.aspx

Comments are welcome...

Thursday, March 8, 2012

"Max Database Size" issue

I'm creating a new SQL CE database on a desktop computer via merge replication with an existing SQL 2005 database. The original database is appx. 270MB, so I set the "max database size" parameter in my connection string to 1024 (which should indicate a max SQL CE database size of 1GB). The initial replication works fine. However, when I open the database from my custom application (which does NOT specify a max database size in its connection string), I get an exception telling me that the database has grown beyond its maximum size.

The documentation for SQL CE seems to indicate that the "max database size" connection string parameter is only examined when the database is originally created or compacted. Is this true, or do I need to specify max database size in the connection string even when opening an existing database?

Thanks in advance for any help or direction anyone can offer!

For the final word on Max database size, see http://blogs.msdn.com/sqlservercompact/archive/2007/06/13/the-story-of-max-database-size-connection-string-parameter.aspx

"lenght cannot be less than zero. Parameter name : lenght"

I'm using Visual Studio 2005, and when i try to drop a table from a data source( SQL Mobile database), to a new or existing form, always occors the error ""lenght cannot be less than zero. Parameter name : lenght"" , my project has more than one forms.
If i make the same steps on a new project with only one form, i can drop the same table without problems.
Anyone can help with this problem?

best regards,

Pedro Nogueira

Pedro,

It sounds like you are using the drag and drop data binding in a Windows Forms application using SQL Mobile as the data source?

First I recommend ensuring that you are running VS2005 Service Pack 1. If you are or still have this issue after upgrading, to recreate

this, we would need some insight into your database schema and how you are doing the drag and drop onto the form (are you dropping

the whole table? are you bound to a datagrid or to another control, etc)

What I'm saying is that I don't hear of anyone having problems with drag & drop of SQL Mobile/SQL CE tables onto forms with

VS2005 SP1, so you either have a bad install or have indeed found a bug. Happy to help you with that but would need more info

on your database and how you're doing the binding.

Darren Shaffer

Friday, February 24, 2012

"Append to Media" Vs "Overwrite an existing media" in SQL Server Database ba

Dear All,

I know the basic defiinition of these two options, but i am not very clear why would someone choose one over another,
currently I am using Append to Media option, and every day backup, I see my backup files growing in size.

can someone give me nice example about these two options,

Thanks,

When you append to the media the previous backups also remain in the backup file. One backup file can contain numerous backups. When you overwrite the backup file is recreated every time so it contains just one file.

WesleyB

Visit my SQL Server weblog @. http://dis4ea.blogspot.com

|||Thanks for your reply.

That means, overwrite backup media will occupy less space, then why would i choose Append to media,

any risk involved in overwriting option ?, becuase every body recommends appending, why not ovewritting.

Thanks,|||

It will definitely use less space.

I do not see the risk of overwriting your backup unless you need a full backup that was taken a couple of days earlier to be accessible. In most cases I suppose you will only be interested in the latest version of your database and not the one you had 3 months ago. For the 'special' occasions where a specific version may be required I would simply take a separate backup.

WesleyB

Visit my SQL Server weblog @. http://dis4ea.blogspot.com

|||

Thanks, your advice is helpful,

but if i want to be able to recover point in time, then I have to go with append to media, along with Transaction long back , RIGHT?

|||

The risk is that if you overwrite the previous backup, and then the current one fails for any reason you are left with no backup for your database. Not a good situation.

What I'd recommend instead, which is a fairly common practice, is to do each backup to a new file which incorporates the current date/time as part of the filename.

That way you always have unique filenames, you can easily prune out old backups, and it's obvious which backup is from what time.

|||

Thanks,

but even if i append to media, and it fails, i will left with no backups , Right?

also for your best suggestion, can you send me sample query or how to do in Enterprise manager.

|||Fahim,
If you are appending to a media daily and if the backup fails today (assumption) then you are atleast left with the backups of previous days since you are appending the previous backups will be present ! but if chose the overwrite option it will overwrite the existing backup file and then will backup the database so if your backup fails due to some reason you are left with no backups for your database.
You can make use of the maintenance plan in sql 2000 to configure backup job and you can specify the number of days to retain the backup file........the backup file will be created with dd/mm/hr format so that it can be deleted by chosing the option "Remove files older than"
http://www.databasejournal.com/features/mssql/article.php/3530486

Friends pls correct me if am wrong Smile

Regards
Deepak