Detect Anomalies Like Exceptional Swings Accross Aggregations?
Nov 9, 2007
Hello,
Not sure if data minimg can help me solving this type of inquiries. Thanks in advance for any pointers you could provide me.
Problem:
We have many dimensions with many levels. Sales directors will sometimes note a drop or a spike when looking at one of the dimensions members, most of the time at a high level.
Example, For Q4 07, the aggregation of Q4 Billing plus remaining Q4 Backlog dropped by $10M in America for the Automotive business from week 4 to week 5 while it was forecasted to remain stable.
The immediate question that will be sent to the guys in charge of this business is "What happened?".
Obviously evyone struggle to answer these questions eveytine there is a drop anywhere.
Using classic tools, they will try to spot a single anomaly or determine if this is accross the board and what are the concurent factors like lower than expected shipments combined with some orders cancellations.
The drop-off can lie in a single product or customer location, in which case it is fairly easy while time consuming to spot the anomaly using classic drill-down approach.
The drop-off can also be more wide spread or caused by a combination of factors like unable to ship in time, orders cancellations and sales credits in which case it is more difficult to spot where is the anomaly and explain it.
So I wonder if there is any way that I could use data mining to make the entire process of detecting anomalies accross dimensions levels, members and measures more straight-forward for end-users.
What do you think?
Thanks,
Philippe
View 1 Replies
ADVERTISEMENT
Feb 21, 2007
Is there an equivalent or similar .net sample for detecting data Anomalies?
Detect Anomalies in Excel
http://zones.advisor.com/doc/14413
View 5 Replies
View Related
Jan 17, 2007
Quick question for you pro's...
Within a report matrix, I want to be able to have different aggregations for totals. One column would be a Sum of the data in that column, the next column would be an Average of the data. Is this possible, or is this not supported in SSR2005?
Thanks in advance for your help,
Clint
View 4 Replies
View Related
May 25, 2008
hi,
I'm making a cube using SSAS and the data in the cube is updated daily. however, each day I take the data with the date of migration because I want to keep the data as history snapshots. the problem is when browsing the data I want to aggregate only the data of a desired date not all the data together. can I define a custom aggregator rather than those found in the properties for the measures?
Thanks a lot.
Mina
View 1 Replies
View Related
May 23, 2008
Hey,
I am trying to add aggregations to the partitions of my cube.
For that, I am using the Aggregation Designer, In which I choose MOLAP partitions with "Performance gain reaches 80%". Next I run the calculation. But the designer found only 78 aggregations and stop at 20% (496 Kb) !
My configuration is SSAS 2005 SP2, x64. Except this problem, everything is allright. Dimension attributes are all aggregatable.
Have you any idea of what can cause such a problem ?
Thanks in advance.
Alex
View 1 Replies
View Related
May 20, 2008
We are trying to compile a difinitive procedure for our customers moving from SSAS 2000 (where we use DSO) to 2005 (where we use AMO). However, we are running into problems getting even the 2000 environment set up according to the specs.
The requirement is a domain environment where the web server and the DB server are 2 different machines. We are replicating this environment locally using 3 Virtual Machines in VMWare Player. All have Windows Server 2003 Enterprise with SP2 installed. One is our domain controller, one is the DB server (SQL Server 2000 and SSAS 2000 SP4 with the hotfix rollup installed) where almost none of our application components are installed, one is the web server with IIS and our ASP.NET application and COM components, which bundles DSO and dependencies, but no database client tools installed. We set up ASP.NET to run as a domain user, a member of Administrators group on the domain and both server machines, and also OLAP Admins on the DB server (we can limit access later once everything works).
I can successfully create the database, cube, dimensions, and partitions from the ASP.NET code calligng COM components written in VB6 which use DSO. However, creating aggregations results in a clipboard error. Here is the code:
1380
Set dsoPartition = m_dsoServer.MDStores(mvarDBName).MDStores(cubeName).MDStores(1)
dsoPartition.OlapMode = olapmodeMolapIndex
1385
' get the partition analyzer
Dim dsoPartitionAnalyzer As DSO.PartitionAnalyzer
Set dsoPartitionAnalyzer = dsoPartition.Analyzer
' initialize the analyzer
dsoPartitionAnalyzer.InitializeDesign
1390
There is more, but the error occurs on one of the three statements between 1385 and 1390
The error is: "Can't open Clipboard" number 521 Source "DSO"
Creating the aggregations via the Storage Design wizard on the DB server directly seems to succeed.
Can somebody help with this?
Thanks,
Boris Zakharin, MCAD
View 1 Replies
View Related
Apr 14, 2006
Fact table gets update every day with thousands of records, I been increase the aggregations manually. Is there a way I can increase aggregations (design storage) programmatically . My cub gets process ones in day with VB program. I want to increase aggregations before processing cub through VB.
It's argent
please help me
thanks
View 8 Replies
View Related
Dec 6, 2007
Can any help me regarding the following
When you are pulling the data from PPV
SELECT
[MATERIAL]
,[IR_AMOUNT]
FROM [LATCUBDAT].[dbo].[ppv]
where [MATERIAL] = 'MR004' AND [IR_AMOUNT] = 53728.85
Result
material
IR_Amount
MR004
53728.85
When you want to join ppv to rmu and then pull the data then
select R.[PRODL]
,P.[MATERIAL]
,P.[IR_AMOUNT] AS 'IR_AMOUNT'
FROM [LATCUBDAT].[dbo].[ppv]P
INNER JOIN [LATCUBDAT].[dbo].[rmu] R ON R.[RAW MATERIAL] = P.[MATERIAL]
where P.[MATERIAL] = 'MR004' AND P.[IR_AMOUNT] =53728.85
PRODUCT LINE
MATERIAL
AMOUNT
30000
MR004
53728.85
32000
MR004
53728.85
36000
MR004
53728.85
50000
MR004
53728.85
52000
MR004
53728.85
54000
MR004
53728.85
When I use avg in the query I get this report
select R.[PRODL]
,P.[MATERIAL]
,avg (P.[IR_AMOUNT]) AS 'IR_AMOUNT'
FROM [LATCUBDAT].[dbo].[ppv]P
INNER JOIN [LATCUBDAT].[dbo].[rmu] R ON R.[RAW MATERIAL] = P.[MATERIAL]
where P.[MATERIAL] = 'MR004' AND P.[IR_AMOUNT] =53728.85
GROUP BY R.[PRODL],P.[MATERIAL]
ORDER BY R.[PRODL],P.[MATERIAL]
PRODUCT LINE
MATERIAL
AMOUNT
30000
MR004
53728.85
32000
MR004
53728.85
36000
MR004
53728.85
50000
MR004
53728.85
52000
MR004
53728.85
54000
MR004
53728.85
I will like to see
PRODUCT LINE
MATERIAL
AMOUNT
30000
MR004
8954.808
32000
MR004
8954.808
36000
MR004
8954.808
50000
MR004
8954.808
52000
MR004
8954.808
54000
MR004
8954.808
If there where 4 product line then avg distributed between 4 and like wise
View 5 Replies
View Related
Mar 30, 2000
Is there anyway that I can run a procedure that will give me all the indexes on tables that are accross multiple servers?
Thanks for any help.
Dianne
View 2 Replies
View Related
Aug 15, 2007
I have 1 table in my db that I have imported from a txt file using DTS.
In my database "DOJ" I have a table named "DOJGRAB" with ALL my data fresh from a import using DTS.
Also in "DOJ" are 6 other tables (NAME, PERSON, etc...)
How can I parse the columns out from my DOJGRAB table to fill existing columns in my other 6 tables? Basically a copy of specific columns from DOJGRAB to their proper places in the other tables.
Can somebody post an example of the syntax I would use to copy a column from one table to another? Thanks!
View 7 Replies
View Related
Mar 14, 2008
I have to DBs. One is the original and the other is for testing. They both have similar data structure. Wanted to know if there is a way to update tables contents in one db with data that is in the other one.
View 4 Replies
View Related
Nov 28, 2006
First thanks for your time.
We have 4 clustered SQL2000 Servers each contains information specific to its application related to customer information in a casino player tracking database. My problem is as follows On the Playertracking database I can join and return information from the tables there with no problems the performance accross the decently sizable transactional based table is pretty decent. The problem is I need to filter this query down by the Type of machine the customer plays. The child key exists in the playertransaction table the parent key is on another server. Here is the lay out of the tables unecessary information from the tables were truncated for brevity.
CREATE TABLE [dbo].[PlayerSession] (
[PlayerId] [int] NOT NULL ,
[Mnum] [int] NOT NULL ,
[CoinIn] [money] NOT NULL ,
[CoinOut] [money] NOT NULL ,
[Games] [int] NOT NULL ,
[Jackpot] [money] NULL ,
[Win] [money] NULL ,
[TheoWin] [money] NOT NULL ,
[PlayerMod] [tinyint] NOT NULL
) ON [PRIMARY]
-- Player Demographics information
CREATE TABLE [dbo].[Player] (
[PlayerId] [int] NOT NULL ,
[Status] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Title] [varchar] (5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[FirstName] [varchar] (40) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[MiddleName] [varchar] (40) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[LastName] [varchar] (40) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[SSN] [varchar] (16) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
) ON [PRIMARY]
--Machine Information that links to Machine Type table
CREATE TABLE [dbo].[Machine] (
[MNum] [int] NOT NULL ,
[MachineTypeId] [smallint] NOT NULL ,
) ON [PRIMARY]
-- Machine type code table
CREATE TABLE [dbo].[MachineType] (
[MachineTypeId] [smallint] NOT NULL ,
[Denom] [int] NOT NULL ,
[Par] [decimal](6, 2) NOT NULL ,
[GameType] [varchar] (40) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
) ON [PRIMARY]
From the server where all the player information is ran I can query the linked database for the machine and machine type information like this.
SELECT m.MNum, mt.MachineTypeId, mt.GameType, mt.DisplayType
FROM ACCTV.Accounting.dbo.Machine m INNER JOIN
ACCTV.Accounting.dbo.MachineType mt ON m.MachineTypeId = mt.MachineTypeId
This is the information I am trying to get out but the query times out on me.
SELECT Player.PlayerId, Player.FirstName, Player.LastName, SUM(PlayerSession.CoinIn) AS sumCI, SUM(PlayerSession.CoinOut) AS SumCO,SUM(PlayerSession.TheoWin) AS SumTheo, AVG(PlayerSession.TheoWin) AS AvgTheo, SUM(PlayerSession.Win) AS SumWin, AVG(PlayerSession.Win) AS AvgWin, mt.GameType
FROM Player INNER JOIN
PlayerSession ON Player.PlayerId = PlayerSession.PlayerId INNER JOIN
ACCT.Accounting.dbo.Machine M ON PlayerSession.Mnum = M.MNum INNER JOIN
ACCT.Accounting.dbo.MachineType mt ON M.MachineTypeId = mt.MachineTypeId
GROUP BY Player.PlayerId, Player.FirstName, Player.LastName, mt.GameType
The other option would be some sort of SubQuery but I dont know how to return results from the subqueries to the root query to be returned to the restulting recordset. I am not necessarily looking for an answer more of looking for a direction to go to find my solution.
Thanks again for your help.
View 1 Replies
View Related
Aug 10, 2007
Hi,
I am newbie in replication,
I have a requirement where need to set upo replication with db such as both dbs are in different domain.
I have created a merge publication with create pulblisher wizard.
I want to use FTP as default location for the snapshot so that from both the domain database can accesss this path and subscriber will take the snapshot from it.
Issue facing like to run the snapshot agent we need to provide windows domain user or machine user but we can't add this user in FTP machine as domain is differnt will not get access on this machine.
I am getting following error:
Message: The replication agent failed to create the directory '\192.168.7.57ftprootuncPARAG-TEST_NORTHWINDSUB_PARAG_PUB20070810185320'.
Stack: at Microsoft.SqlServer.Replication.Utilities.CreateDirectoryWithExtendedErrorInformation(String directory)
at Microsoft.SqlServer.Replication.Snapshot.SnapshotProvider.CreateSnapshotFolders()
at Microsoft.SqlServer.Replication.Snapshot.MergeSnapshotProvider.CreateSnapshotFolders()
at Microsoft.SqlServer.Replication.Snapshot.SqlServerSnapshotProvider.GenerateSnapshot()
at Microsoft.SqlServer.Replication.SnapshotGenerationAgent.InternalRun()
at Microsoft.SqlServer.Replication.AgentCore.Run() (Source: MSSQL_REPL, Error number: MSSQL_REPL52026)
Get help: http://help/MSSQL_REPL52026
Source: mscorlib
Target Site: Void WinIOError(Int32, System.String)
Message: Logon failure: unknown user name or bad password.
Stack: at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.Directory.InternalCreateDirectory(String fullPath, String path, DirectorySecurity dirSecurity)
at System.IO.Directory.CreateDirectory(String path, DirectorySecurity directorySecurity)
at Microsoft.SqlServer.Replication.Utilities.CreateDirectoryWithExtendedErrorInformation(String directory) (Source: mscorlib, Error number: 0)
Any help regarding this is appreciable.
Please can put more light on it if I am doing anything wrong.
Thanks & Regards
Amit Harhare
View 5 Replies
View Related
Jul 23, 2005
"David Portas" <snipped for brevity> wrote:Example 1:[color=blue]>> UPDATE table_a> SET col = ? /* Unspecified */> WHERE EXISTS> (SELECT *> FROM table_b> WHERE table_b.key_col = table_a.key_col)>[/color]<snip again>Many thanks. I have used this sample extensively since you posted it. Hopeyou (or someone) can help me with one more thing: How would it be writtento update several fields in table A with data from table B, where as youhave shown, a column matches the records?TIA!~ Duane Phillips.
View 4 Replies
View Related
Sep 21, 2007
Are there any perfmonace or query optimization limitations or issues that arise when issueing a fully qualified query across multiple databases on the same Instance of SQL Server. In other words are all features of query optimization fully supported in queries that span databases on the same Instance.
View 3 Replies
View Related
Nov 1, 2007
Hello, all
I have developed a SSIS package using a transaction
1. Users upload excel file to web server(139.223.15.xxx)
2.Excute SSIS package in web server to import excel file to SQL SERVER 2005(139.223.3.xxx)
If web server and SQL server are in the same network zone, the package will work successfully.
However, the two servers are in the different network zone, it encounters an error :
DTS can't enlist OLE DB in distribution transaction. Error Code: 0x8004D00E
How do I set any configurations?
Environment:
Web server:windows 2003 server sp1 ent
SQL server 2005 ent:windows 2003 server sp1 ent
SSIS: isolation level-->read committed
View 1 Replies
View Related
Apr 20, 2007
Hi,
Is there a way to take a snapshot of a table at precisely the same time on multiple servers and write the table snapshot to another 'work' database? I'm asking in this forum hoping that perhaps SSIS has a built in tool to help with this. I'm wanting to audit table(s) accross seven different servers. In order to do this I want to make sure that I have the table at the same moment in time on all the servers. I plan on using the tablediff utility to then compare each table on each server against one another. If somebody knows a better method to do this please let me know.
Thanks,
Phil
View 1 Replies
View Related
Sep 25, 2006
We are in the midst of cleaning up database01. There are objects in database01 that are widely used in store procedures that reside in database02.
Problem is: I need to know which tables and view from database01 are in use by store procedures in database02. This is important because if I accidently decommission tables that are currently in use by production class s-procedures, it will not be pretty. A sample output could look like:
StoreProc UsingObject
sp001 ctblCodeName
sp002 tblUnitSales
so003 tblSalesTrans
.......... .................
I am not a programmer and none of our programmers here claim that there is any solution to this problem without spending thousands on s/w licenses. Any simple solution + code snippet that will help me resolve this problem by myself would be incredibly valuable.
In disstress and frustration . . . .
JJOSHI
View 4 Replies
View Related
Dec 8, 2006
Hi,
We have SAN for our SQL server and all of DB backup copy pointing to one the SAN volume(ex. T). We are moving the bkp copy from this SAN volume into remoteserver for restoring the backup. We are getting a lot of Time out during this time.
Is that copy process affect production time out?.
Thanks,
View 1 Replies
View Related
Apr 19, 2007
Hello,
We have an environment with 7 servers that are running replication with one another and I'm wondering if there are any tools or experiences that any of you might have that may assist in the auditing of these servers. The data should be in synch accross the boards for all tables, but sometimes problems can arise such as replication not being set up properly, stored procedure's being out of synch, or data gliches etc.
In dealing with these issues we have an in-house written program which analises each table on each server and takes a snapshot and does column by column compare. We also have another program that will synch the data up (basically a delete/insert statement on the publisher). This process can take up to 3 weeks for our quarterly update of every table. I'm wondering if anybody has used any tools such as in SSIS or a third party tool and has done or is doing something similar to what we are doing now. If so, are there any tips you wouldn't mind sharing on how our process might be sped up?
Thanks,
Phil
View 4 Replies
View Related
Sep 13, 2007
Hi,
I'm trying to create a database that takes specific information from a number of databases on different servers to make some reporting that we have much easier.
I'm pretty new to SQL so I'm not sure of the best way to proceed. I read an article that suggested I use the OPENROWSET command. The problem is, the version of SQL that came with one of the programmes we use is limited and will not allow you to turn on the allow "Ad Hoc distributed Queries" so the SLQ statement will not execute.
I'm confused why it won't let me to connect through ODBC as I've created a web page that selects data from this database with no problems!
Here is the SQL statement that I've written to make sure it is the correct one (on the msdn library page it said that this was the ODBC connection):
SELECT a.*
FROM OPENROWSET('MSDASQL','DRIVER=(SQL Server);SERVER=APPOLOACT7;UID=sa;PWD=***************',
'SELECT * FROM MDCTestAndDev.dbo.TBL_CONTACT') AS a
I've also created the ODBC connection using the tool on Administration Tools>Data Sources ODBC
Any help would be greatly appreciated (also any ways of selecting from one database and inserting it into another will be helpfull)
Thanks
View 8 Replies
View Related
Jul 20, 2005
HelloI´m using MS-SQL Server 2k with a custom application connecting to it.I need a quick and simple way to detect any change (insert, update, delete)to my database (not just to a single table). The purpose is to notifysomehow different instances of the application about the data changes,since they should refresh their local query results.Is there any function, stored procedure, system database entry, etc. I canexploit to get the job done? Can you suggest me the most suitable mechanismto implement this?T.I.A.AndreA
View 1 Replies
View Related
May 29, 2007
I am entering to administration of
SS2005 SP1 (Windows 2003) having files mdf, ndf, ldf in
C:Program FilesMicrosoft sql serverMSSQLData
This dir also has two *.cer files.
Apparently no encryption is used
How can I get known what these *.cer files are for?
View 4 Replies
View Related
Aug 4, 2006
Hello
I am trying to find out if versions of SQL SERVER 2005 we have installed have full or Developer Licenses.
They were installed previously by someone who no longer works here, and we do not the versions on record.
We have enough full licenses, so we just want to make sure the correct ones are set up on our servers.
Anyone know how/where we can find this information?
View 1 Replies
View Related
Oct 29, 2005
Hi,I want to check with VB.net whether a field in a SQL-table is NULL or not.This code doesnot work:If xxx = NULL then<statements>End IfI got the error, that NULL is not supported ?How do I code the check ???Help is appreciated, Gr.
View 2 Replies
View Related
Jul 22, 2006
hi, good day, i facing a problem
Code:
CREATE PROCEDURE [SP_TEST]
AS
SELECT *
INTO #TMP_CUSTOMER
FROM O_CUSTOMER
-------------------------------------------------------------------------
SELECT DISTINCT
COUNT(CUST_CD)
FROM
#TMP_CUSTOMER
GO
when i run in query analyzer , using "exec SP_TEST" , it work and display result
but when run
Exec Master..xp_CmdShell 'bcp "exec mydbtest..SP_TEST " queryout C:TEST.TXT -c -Slocalhost -Usa -Ppassword'
it give error "SQLState = S0002, NativeError = 208"
and show
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name '#TMP_CUSTOMER'.
thanks for guidance
View 4 Replies
View Related
Oct 30, 2002
Hassle free locating / reporting or deletion of duplicate rows in a SQL table based on the uniqueness of a column or columns that the user provides with a few nifty hands off features. Keywords: delete unique column record records
(This code may also be viewed at http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=576&lngWId=5
/*Description: UTILITY - Locate in MASTER
Syntax: EXEC sp_RemoveDups TableName, DupQualifierFieldNameList, DeleteDups, UniqueColName, CreateIdentColIfNeeded, StoredProcedureResult
Only the first two arguments are required
For HELP, enter the stored procedures name without any arguments or see the PRINT statements below
NO DELETION WILL OCCUR by default - only duplicate recordset returned. To delete records, pass in a 0 for the DeleteDups argument.
Example: EXEC sp_RemoveDups 'MyTable','LastName,FirstName,HomePhone'
Purpose: Allow removal of duplicate rows where
1. We define what fields qualify the duplicate
2. We select the unique rowid or it is detected automatically else no action takes place
Method:Delete by RowID all duplicate rows except the highest RowID (in alpha-sort sequence)
of each group of duplicates.
DATEBYCHANGE
09-23-2002FrankOriginal v1.0
09-23-2002FrankChanged the name from sp_RemoveDupsByRowID to sp_RemoveDups
10-8-2002Sean P. O. MacCath-MoranMade @UniqueColName optional
Added logic to auto-detect RowGUID and Identity columns
Added logic to check for unique value column if no RowGUID or Identity column exists
Added logic to create a temporary ID field as a last resort if no unique column could be located
Added HELP
*/
CREATE PROCEDURE sp_RemoveDups
@TableName as varchar(50) = NULL,
@DupQualifierFieldNameList as varchar(200) = NULL,
@DeleteDups as bit = NULL,
@UniqueColName as varchar(50) = NULL,
@CreateIdentColIfNeeded as bit = NULL,
@StoredProcedureResult int = NULL OUTPUT
AS
SET NOCOUNT ON
DECLARE @SQL nvarchar(2000)
DECLARE @SQL_DetermineUniqueTemplate nvarchar(2000)
DECLARE @TempIdentColName varchar(20)
DECLARE @HostName varchar(50)
DECLARE @ActionText varchar(10)
DECLARE @SUM int
DECLARE @COUNT int
DECLARE @NextColumn varchar(50)
/*==================================================================================*/
/*========================VARIABLE INITIALIZATION AND SETUP========================*/
/*=================================================================================*/
/*If no unique column is located then a temporary Identity column will be created useing the name specified in this TempIdentColName string*/
SET @TempIdentColName = 'TempIdentityColXY123'
SET @SQL_DetermineUniqueTemplate = 'SELECT @COUNT = COUNT(Count), @SUM = sum(Count) from '
SET @SQL_DetermineUniqueTemplate = @SQL_DetermineUniqueTemplate + CHAR(13) + '(SELECT TOP 100 PERCENT <COLUMN_NAME>, COUNT(*) as Count FROM ' + @TableName
SET @SQL_DetermineUniqueTemplate = @SQL_DetermineUniqueTemplate + CHAR(13) + ' GROUP BY <COLUMN_NAME> ORDER BY <COLUMN_NAME>) a'
/*Retrieve the Host Name. This will be used later in this SP as a test to determine if the user is making this call from within SQL Query Analyzer*/
SELECT @HostName = hostname FROM master..sysprocesses WHERE spid = @@SPID AND program_name = 'SQL Query Analyzer'
/*Set ActionText to be used in message output*/
IF (@DeleteDups IS NULL) OR (@DeleteDups = 1)
SET @ActionText = 'Selection'
ELSE
SET @ActionText = 'Deletion'
/*If a value is specified for use by UniqueColName it cannot exist in the columns from the DupQualifierFieldNameList*/
IF CHARINDEX(@UniqueColName, @DupQualifierFieldNameList) > 0
BEGIN
/*The value in UniqueColName was detected in DupQualifierFieldNameList.*/
IF NOT (@HostName IS NULL) PRINT 'The UniqueColName provided (' + @UniqueColName + ') must not exist in DupQualifierFieldNameList (' + @DupQualifierFieldNameList + '). Other solutions will be sought automatically.'
SET @UniqueColName = NULL
END
/*If UniqueColName is provided then perform check to ensure that all the values in that column are, in fact, unique.*/
IF NOT (@UniqueColName IS NULL)
BEGIN
SET @SQL = REPLACE(@SQL_DetermineUniqueTemplate,'<COLUMN_NAME>', @UniqueColName)
/*Perform a check of this column to determine if all of it's values are unique*/
EXEC sp_executesql @SQL, N'@SUM as int OUTPUT,@COUNT as int OUTPUT',@SUM OUTPUT,@COUNT OUTPUT
/*Test to determine if this column contains unique values*/
If @SUM <> @COUNT
BEGIN
/*The column specified by UniqueColName does not contain unique values.*/
IF NOT (@HostName IS NULL) PRINT 'The UniqueColName provided (' + @UniqueColName + ') does not contain unique values. Other solutions will be sought automatically.'
SET @UniqueColName = NULL
END
END
/*==============================================================*/
/*======================HELP OUTPUT TEXT======================*/
/*==============================================================*/
IF (@TableName IS NULL) OR (@TableName = '/?') OR (@TableName = '?') OR (@DupQualifierFieldNameList IS NULL) OR (@DupQualifierFieldNameList = '/?') OR (@DupQualifierFieldNameList = '?')
BEGIN
IF NOT (@HostName IS NULL)
BEGIN
PRINT 'sp_RemoveDups ''TableName'', ''DupQualifierFieldNameList'', [''DeleteDups''], [''UniqueColName''], [''CreateIdentColIfNeeded''], <''StoredProcedureResult''>'
PRINT '====================================================================================================================================================================='
PRINT 'TableName: Required - String - Name of the table to detect duplicate records in.'
PRINT 'DupQualifierFieldNameList: Required - String - Comma seperated list of columns that make up the unique record within TableName.'
PRINT 'DeleteDups: Optional - Bit, Set to 0 to delete duplicate records. A value of NULL or 1 will return the duplicate records to be deleted.'
PRINT 'UniqueColName: Optional - Bit - A table must have a unique column value in it to perform the deletion logic. If no UniqueColName is provided then an attemp will be made to locate the RowGUID column. If that fails then an attempt will be made to locate the Identity column. If that fails then all of the columns of the table will be examined and the first one with all unique values will be selected.'
PRINT 'CreateIdentColIfNeeded: Optional - Bit - By default this SP will create an identity column if no unique column can be located. Pass in a 1 here to run this feature off.'
PRINT 'StoredProcedureResult: Optional - OUTPUT - Int - Returns a 3 if an error occured, otherwise returns a 0.'
END
SET @StoredProcedureResult = 3
RETURN
END
/*========================================================================*/
/*======================DETECT USABLE UniqueColName======================*/
/*========================================================================*/
IF @UniqueColName IS NULL
BEGIN
/*Check for a RowGUID or Identity column in this table. If one exists, then utilze it as the unique value for the purposes of this deletion*/
IF EXISTS(SELECT * FROM SysColumns WHERE ID = Object_ID(@TableName) and ColumnProperty(ID,Name,'IsRowGUIDCol') = 1) SET @UniqueColName = 'RowGUIDCol'
IF EXISTS(SELECT * FROM SysColumns WHERE ID = Object_ID(@TableName) and ColumnProperty(ID,Name,'IsIdentity') = 1) SET @UniqueColName = 'IdentityCol'
IF @UniqueColName IS NULL
/*If no RowGUID or Identity column was found then check all of the columns in this table to see if one of them can be utilized as a unique value column*/
BEGIN
/*Select all of the columns from the table in question...*/
DECLARE MyCursor CURSOR LOCAL SCROLL STATIC FOR SELECT name FROM syscolumns WHERE OBJECT_ID(@TableName)=ID
OPEN MyCursor
FETCH NEXT FROM MyCursor INTO @NextColumn
WHILE @@fetch_status = 0
BEGIN
/*Create SQL string with correct column name in place.*/
SET @SQL = REPLACE(@SQL_DetermineUniqueTemplate,'<COLUMN_NAME>', @NextColumn)
/*Perform a check of this column to determine if all of it's values are unique*/
EXEC sp_executesql @SQL, N'@SUM as int OUTPUT,@COUNT as int OUTPUT',@SUM OUTPUT,@COUNT OUTPUT
/*Test to determine if this column contains unique values*/
If @SUM = @COUNT
BEGIN
/*A unique values column is detected. Use it and break out of the loop UNLESS column is specified in DupQualifierFieldNameList*/
IF CHARINDEX(@NextColumn, @DupQualifierFieldNameList) = 0
BEGIN
/*NextColumn was NOT detected in DupQualifierFieldNameList, so this is the column we will use.*/
SET @UniqueColName = @NextColumn
BREAK
END
END
ELSE
FETCH NEXT FROM MyCursor INTO @NextColumn
END
CLOSE MyCursor
DEALLOCATE MyCursor
END
END
/*If no UniqueColName has been found then create one UNLESS @CreateIdentColIfNeeded = 1*/
IF (@UniqueColName IS NULL) AND ( (@CreateIdentColIfNeeded IS NULL) OR (@CreateIdentColIfNeeded = 0) )
BEGIN
/*Add a sequence column to the table...*/
IF NOT (@HostName IS NULL) PRINT 'Creating temporary identity column in the ' + @TableName + ' table named ' + @TempIdentColName + ' for use in this ' + LOWER(@ActionText) + ' process...'
EXEC('ALTER TABLE ' + @TableName + ' ADD ' + @TempIdentColName + ' [int] IDENTITY (1, 1)')
SET @UniqueColName = @TempIdentColName
END
/*============================================================================*/
/*======================EXECUTE DELETION OR SELECTION======================*/
/*===========================================================================*/
IF @UniqueColName IS NULL
BEGIN
/*No UniqueColName was provided by the user and none were detected by the script. This deletion algorythm cannot run.*/
IF NOT (@HostName IS NULL) PRINT 'Could not perform ' + LOWER(@ActionText) + ' process. No unique columns were located and the UniqueColName flag is set to 1 (False).'
SET @StoredProcedureResult = 3
RETURN
END
ELSE
BEGIN
IF NOT (@HostName IS NULL) PRINT 'Performing ' + LOWER(@ActionText) + ' utilizing the unique values in the ' + @UniqueColName + ' column as a reference...'
/*
Create and execute an SQL statement in the form of:
SELECT * (or DELETE)
FROM TableName WHERE UniqueColName IN
(
SELECT UniqueColName FROM TableName WHERE UniqueColName NOT IN
(
SELECT MAX(Cast(UniqueColName AS varchar(36))) FROM TableName GROUP BY DupQualifierFieldNameList, DupQualifierFieldNameList, etc
)
)
*/
/*Delete all duplicate records useing @UniqueColName as a unique ID column */
IF (@DeleteDups IS NULL) OR (@DeleteDups = 1)
SET @SQL = 'SELECT * '
ELSE
SET @SQL = 'DELETE '
SET @SQL = @SQL + 'FROM ' + @TableName + ' WHERE ' + @UniqueColName + ' IN '
SET @SQL = @SQL + CHAR(13) + CHAR(9) + '(' + CHAR(13) + CHAR(9)
SET @SQL = @SQL + 'SELECT ' + @UniqueColName + ' FROM ' + @TableName + ' WHERE ' + @UniqueColName + ' NOT IN '
SET @SQL = @SQL + CHAR(13) + CHAR(9) + CHAR(9) + '(' + CHAR(13) + CHAR(9)+CHAR(9)
SET @SQL = @SQL + 'SELECT MAX(Cast(' + @UniqueColName + ' AS varchar(36))) FROM '
SET @SQL = @SQL + @TableName + ' GROUP BY ' + @DupQualifierFieldNameList
SET @SQL = @SQL + CHAR(13) + CHAR(9) + CHAR(9) + ')' + CHAR(13) + CHAR(9) + ')'
EXEC (@SQL)
IF @@ERROR <> 0
BEGIN
IF NOT (@HostName IS NULL) PRINT @ActionText + ' process failed.'
SET @StoredProcedureResult = 3
END
ELSE
BEGIN
IF NOT (@HostName IS NULL) PRINT @ActionText + ' completed successfully with this SQL: ' + CHAR(13) + @SQL
SET @StoredProcedureResult = 0
END
END
IF (@UniqueColName = @TempIdentColName) AND ( (@CreateIdentColIfNeeded IS NULL) OR (@CreateIdentColIfNeeded = 0) )
BEGIN
/*Remove the sequence column from the table...*/
IF NOT (@HostName IS NULL) PRINT 'Removing temporary identity column named ' + @TempIdentColName + ' from the ' + @TableName + ' table...'
EXEC('ALTER TABLE ' + @TableName + ' DROP COLUMN ' + @TempIdentColName)
END
GO
Edited by - emanaton on 10/30/2002 11:28:34
View 11 Replies
View Related
May 16, 2006
Hello,how I can detect via code (C++, C#) which sql servers like oracle, mssql,mysql are close to me and connectable within one or two second (timeout towait for answers should be variable)?Thank you.regardsMark
View 3 Replies
View Related
Apr 24, 2008
Hi Guys,
I need to detect what version/ or versions of SQL Server are installed on a machine before I can install my software. I am currently looking for SQL Server 2000 / SQL Server 2005 /SQL Server Express Edition & SQL Server 2008 CTP (for the time). How do I find this out. Is SQL-DMO the way forward or should this be some WMI script. I would appreciate any pointers/scripts etc.
I have read a lot of people mentioning using @@version from a query window but as I need the software to do this on first start up can this work for all versions
Thanks in advance
View 7 Replies
View Related
May 17, 2006
Running SQLEXPR_ADV.EXE against Windows XP SP0 causes the setup to exit gracefully with a message indicating the the right service pack is not installed.
However, running SQLEXPR_ADV.EXE against Windows XP SP1 does not exit and continues to install. Then, when you try to run a script against the installation, you get the message:
[Microsoft][ODBC SQL Server Driver][DBMSLPCN][SQL Server does not exist or access denied].
This will become very problematic when installing SQL Server Express as the database for small installations.
The setup really needs to be updated to look for all the system requirements that it can detect. Evidently it can detect the Service Packs. The Wise Installer is not able to script that requirements unless there is some way to make the Windows Installer look for it that is not documented.
Pat
View 3 Replies
View Related
Jan 11, 2008
I need to make a control in a trigger, but there is a sequence of N INSERT inside oneself transaction and I should only control when it is the last register.
I ignore the quantity of INSERT, it can be one or several. And in the values there is not any indicator that allows me to deduce if it is the last one.
It would seem that I need a trigger for COMMIT...
Is there some form of making this?
View 3 Replies
View Related
Jan 29, 2007
I have written a .NET application that uses SQL Server Compact Edition. It's deployed by a MSI file (setup project in VS - not ClickOnce).
How do I add a SQL CE launch condition to my setup project?
View 1 Replies
View Related
Jan 29, 2008
How to Detect whether installed the sqlce 3.5 RTM or not ?
View 7 Replies
View Related