Showing posts with label project. Show all posts
Showing posts with label project. Show all posts

Thursday, March 8, 2012

Aggregate Query Problem

Hey there,
In a simple project and among my datasets, there's one(StorageDs) that represents two tables in the db. StorageInput and StorageOutput. Each time an amount of a certain ingredient is bought, a new row is added to the StorageInput table and same thing for StorageOutput when it is sold. Now, in my dataset, there's a sorta aggregate table adapter that takes the ingredients with a certain IngredientIDs from StorageInput, sums the up, takes the same ingredientID from StorageOutput table and subtracts them to yield what is left. Here's the query:

SELECT IngredientID, SUM(INPUTS) AS InputSum, SUM(OUTPUTS) AS OutputSum, SUM(INPUTS) - SUM(OUTPUTS) AS TotalSum
FROM (SELECT StorageInput.Units AS INPUTS, StorageOutput.Units AS OUTPUTS, StorageInput.IngredientID
FROM StorageInput INNER JOIN
StorageOutput ON StorageInput.IngredientID = StorageOutput.IngredientID) AS IOSUM
GROUP BY IngredientID

but something weird happens! For instance when the Sum of StorageInput is supposed to be 50 for a certain ingredient, the first time I execute the query the sum of StorageInput for that ingredient is reported as 100, next time 150 and so on.
Basically, I guess what the query does every time is add the sum of StorageInput to itself one extra time!
It'd be great if anyone could help me with this.
Thanks a lot.

Do you get the same behavior when execute via query analyzer or sql mgmt studio?

A select statement should just the return the data it finds in the database. It does not maintain a running sum just because you run it multiple times. I suggest you double check your client code to make sure your dataset/adapter/variable is handled correctly.

|||oj, thanks for your reply. I forgot to mention that I'm giving SQL EXPRESS a try. So I can't test the query with Query Analyzer or Management Studio for that matter. All I'm able to do is test the query with Query Builder or Preview Data in VS and they both return incorrect values. Considering this, I suppose checking the client code is also out.
|||

You should be able to connect to sqlexpress from QA or Mgmt. If the instance is on the same machine as QA, you can use ".\sqlexpress" as the server name. If it's on a remote node, you will have enable sqlexpress to allow remote connection. Launch Surface Area Conf to change the setting.

Friday, February 24, 2012

Ageing data using Sql Server 2000

Hi there,

I've only recently started a project using sql server 2000 for the
first time. One of the considerations we have to take is that we need
to continuously age/purge data from a couple of large tables (100
million rows+) - to keep the tablesize growth to a minimum. Coming
from an Oracle background, I've used partitions to help manage this
before.

Now with Sql Server 2000, I'm wondering what the best/recommended
approaches are for ageing data - I've been struggling to find out
enough inforamtion on the msdn site, so I'm hoping some gurus out
there can help me here.

Thanks![posted and mailed, please reply in news]

elpico (kevinmartinwalsh@.yahoo.co.uk) writes:
> I've only recently started a project using sql server 2000 for the
> first time. One of the considerations we have to take is that we need
> to continuously age/purge data from a couple of large tables (100
> million rows+) - to keep the tablesize growth to a minimum. Coming
> from an Oracle background, I've used partitions to help manage this
> before.
> Now with Sql Server 2000, I'm wondering what the best/recommended
> approaches are for ageing data - I've been struggling to find out
> enough inforamtion on the msdn site, so I'm hoping some gurus out
> there can help me here.

Partitioned views may be your best bet. You would have one table each
for each chunk you want to prune at a time. (You would have to know the
size of the chunk before you start inserting the data, obviously.) Each
table would have a check constraint on the primary key which constrains
the table to its partition, and then you combine all tables into a view
by means of UNION ALL.

Provided that you follow certain rules you can insert directly through
the view. You can also use a INSTEAD OF triggers that divert the data
into the approriate table.

Each time you need to add a new partition, you would need to alter
the view, and possibly also alter the constraint for the primary key
for the top-most table. But you could create partitions long before you
actually need them, to make this a swift operation.

I've only given you a brief introduction. Use the index in Books Online to
find "partitioned views" to get more information.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp

Sunday, February 12, 2012

After deploying a Business Intelligence project how to recreate the OLAP security

During development the project is focus on schema and schema changes and test

security. When I I deploy the database to production, I end getting

the development security in the production database. How does one create

a script that recreates the security in the production environment so that I can

be reused it after the deployment. The synchronziation wizard is not appropriate

since it moves data as well.

In SQL

Server Management Studio you can access Script related menu commands from the

context menu. All management dialogs in that program also have Script button on

the toolbar. An object can be scripted and script re-executed on another

server.

Additionally you can import entire database as a BI Development project using. In

BI Development Studio - menu File | New | Project and choose the project of

type "Import Analysis Services 9.0 Database". That imported solution

can be adjusted and deployed onto another server.

|||

I not sure what is meant by context senstive menus? I was hoping for a faster method.

I know that what I ending up doing was for each role in the production database Roles Heading:

I right clicked on the properties of the role and then selected the "Cubes" page and then clicked the Script Action menu.

This took 3 hours to do for all of the production roles:

I am not sure I understand the second choice since I did this at the beginning of the project, removed all of the

production security, made hundreds of changes to cubes and dimensions and readded the development security interactively.

|||You actually did what i meant. Performance is another story.

After creating database, running script to create tables?

I am in my apps master database and I have a Proc to create a project database. However, once that database is created, I have a long script that I need to run to create the tables, indexes, and views.

What is the best way to run this?

I'd intended to just make this part of my stored proc -- create database, then tables, then views. However, to simply create the database, I had to build a string to concatenate the passed in value of the new database. I'd hate to have to do this for every line of this script.

Should I simply take this script as is and create it as a stored proc in the new database and then run that proc?Well, you don't need to store it as a stored procedure in order to run it. You could just switch to the new database and run it through Query Analyzer. Alternatively, you could put a USE database statement at the beginning of the script, and that would switch the database focus for you. (You'll want to make sure it succeeds though, because otherwise you could end up creating all your objects in the Master database.)

Is this supposed to be part of an automated process?

blindman|||Originally posted by blindman
Well, you don't need to store it as a stored procedure in order to run it. You could just switch to the new database and run it through Query Analyzer. Alternatively, you could put a USE database statement at the beginning of the script, and that would switch the database focus for you. (You'll want to make sure it succeeds though, because otherwise you could end up creating all your objects in the Master database.)

Is this supposed to be part of an automated process?

blindman

Yes. I'm trying to allow admin users on our web app the ability to create new projects on the fly. Part of this is creating the new database.|||Originally posted by blindman
Well, you don't need to store it as a stored procedure in order to run it. You could just switch to the new database and run it through Query Analyzer. Alternatively, you could put a USE database statement at the beginning of the script, and that would switch the database focus for you. (You'll want to make sure it succeeds though, because otherwise you could end up creating all your objects in the Master database.)

Is this supposed to be part of an automated process?

blindman

Bummer: Server: Msg 154, Level 15, State 1, Procedure CreateclaimDexDB_SP, Line 22
a USE database statement is not allowed in a procedure or trigger.|||No, USE is not allowed in a procedure or trigger. I've gotten around that in the past by creating dynamic SQL statements, but I imagine your code is rather long for that.

Personally, I think this is only one of the drawbacks you will encounter by creating separate databases for each project. By far the easiest way to handle an application like this is to add scalability to your database to allow it to handle multiple projects. This will make it much faster and easier to add, delete, and manage projects. It will also prevent a lot of duplicated information between databases which are sure to get our of synch, and will allow for powerful comparison analysis between projects.

I think you are heading into an administrative nightmare by creating separate databases, and this problem that you have now is just the tip of the iceberg.

It is also not a good idea to be storing procedures like this in the master database. If you must, then create a separate database to store the procedures involved in creating project databases.

Other options include using SQL to load a template database from a backup file. The template database could have all your objects already stored.

...or your front end application could switch focus to the new database before executing the procedure for creating all the objects.

blindman|||Originally posted by blindman
No, USE is not allowed in a procedure or trigger. I've gotten around that in the past by creating dynamic SQL statements, but I imagine your code is rather long for that.

Personally, I think this is only one of the drawbacks you will encounter by creating separate databases for each project. By far the easiest way to handle an application like this is to add scalability to your database to allow it to handle multiple projects. This will make it much faster and easier to add, delete, and manage projects. It will also prevent a lot of duplicated information between databases which are sure to get our of synch, and will allow for powerful comparison analysis between projects.

I think you are heading into an administrative nightmare by creating separate databases, and this problem that you have now is just the tip of the iceberg.

It is also not a good idea to be storing procedures like this in the master database. If you must, then create a separate database to store the procedures involved in creating project databases.

Other options include using SQL to load a template database from a backup file. The template database could have all your objects already stored.

...or your front end application could switch focus to the new database before executing the procedure for creating all the objects.

blindman

I appreciate your comments, but in this case, separate databases is the right way to go. They truly are for distinct projects, clients, etc. and CAN be scaled across different servers if need be. In addition, some tables will start out the same, but can be altered by each client independently. This is tying into another existing application.

When I said master DB, I forgot there was a SQL database called master. I meant the main application database, which keeps track of the different projects, users, clients, etc.

As a general rule, I would agree with you, but in this case, we're doing the right thing.

Thursday, February 9, 2012

Advice on technologies

Hi all,

I'm about to embark on a new project and I'm having a few troubles deciding what .NET technologies I need to learn and employ.

The system will be built around SQL Server.

It will involve a client application that will be used to gather data offline using MSDE, then sync back up with the online DB. This will then have a web front-end for users not employing the client app.

I'm pretty fine with the whole front-end and data manipulation thing, but I don't know where to start with the synchronisation.

Could someone please tell me how I should go about getting the systems to communicate? Do I need to use Web Services and do it by XML? Message Queueing? Or are there simpler ways?

Thanks!Try this url it is Microsoft Implementation of MVC(Model View Controller) pattern. Hope this helps.

http://www.microsoft.com/hk/msdn/seminar/download.mspx

Kind regards,
Gift Peddie|||Sorry I was not very specific the MVC(Model View Controller) implementation was the June 30th 2004 presentation. Another presentation you may want to look at is the March 31th 2004 presentation it uses most of the known Patterns but it is n VB. Hope this helps.

Kind regards,
Gift Peddie