Showing posts with label create. Show all posts
Showing posts with label create. Show all posts

Friday, March 30, 2012

KPI that compares the growth over years

Hi there,
I'm new to SSAS and MDX. Creating my first dimensions and cubes went fairly fine. But now I hang on KPI.
I'm trying to create a KPI which shows the growth of bookings comparing one year to the previous year.
I want to set a fiterexpression for the time-dimension (e.g. YearString equals 1998). If a filter is set, it should show the bookings for that year ([Measures].[Bookings]) as value and the bookings of the previous year as goal.
My problem is, that I cannot access the selected YearString, to get the bookings of the previous year. I tried the function parallelPeriod() and also a self-created Calculation, but it seems that [dimension time].[hierachy].CurrentMember is always [dimension time].[hierachy].[(All)].

My data structure is as followed:

Fact-table: FactBookings
SeasonID (FK)
YearID (FK)
AgencyID (FK)
CountryID (FK)
RegionID (FK)
IncomeID (FK)
AgeID (FK)
AgencyID (FK)
Bookings

Dimensions:
Income, Age, Agency:
[dimensionname]ID
[dimensionname]String

Dimension geography (having a hierarchy):
RegionID
CountryID
RegionString
CountryString
primary key: RegionID+CountryID

Dimension time (having a hierarchy):
YearID
SeasonID
YearString
Season String
primary key: YearID+SeasonID

Is there a way to access the filterexpressions for a KPI, or does anyone has an idea, how a calculation might has to be, which shows the value of the previous year compared to the actual year?

It would be very nice, if anybody could give me an idea how to create such a KPI.

Regards,
Maik.

First, you need to create the calculated member for the PreviousYear. You can use either Time Intelligence Wizard, you use formulas from the following blog post: http://www.sqljunkies.com/WebLog/mosha/archive/2006/10/25/time_calculations_parallelperiod.aspx

After that, you can enter the expression for KPI as (Time.PreviousYear, Measures.Booking) and it should work fine.

HTH,

Mosha (http://www.mosha.com/msolap)

|||Thank for your answer.
I've tried it for hours.
Now I have a dimension [Time Calculations]
with a calculated member:
CREATE [Time Calculations].[Prior Year] =
(ParallelPeriod([Dimension Time].[YearString - SeasonString].[YearString]), [Time Calculations].[Current Period]);

But for my KPI something like
([Time Calculations].[Prior Year], [Measures].[Bookings])
as the goal-expression wasn't working.

Finally, after turning IsAggregatable to false for YearString in dimension time, I was able to select a year at the KPI-Browser and the goal-expression showed up the measure-value of the previous year. Yeah! .
But I'm still not completely happy. Because of turning IsAggregatable to false, the measure in the Cube-Browser is fixed either to the first year or to one year specified as a filter.
At this point I'm unable to summarise/aggregate the bookings over all time or more than one year.

Any idea for that?

BTW: nice blog Mosha .|||You shouldn't have had to set IsAggregatable to False on Year attribute. Just remember - when it is aggregatable - you will have All level, so the current member inside your Time dimension will be All Years, so you will need to manually position to specific year in order to see a previous year.

KPI Help Required-I want a revenue report with average Daily Revenue

Hi All,

What I am trying to do is create a average daily revenue KPI using vs.net 2005.

The necessary fields from my fact table are Revenue and the datetimeID, there will be multiple entries perday.

I would like my KPI to check if we are hitting a $10,000 daily average in revenue. But I need to know how many Distinct Days are being calcuated. If I were using regular SQL I could use:

COUNT( SELECT DISTINCT dayNumberOfMonth,monthNumberOfYear,YearNumber)
or
COUNT(SELECT DISTINCT LEFT(datetimeAlternateKey,10))

My Current Datetime Table contains:
datetimeID
fulldatetime
monthNumberOfYear
calendarYear
dayNumberOfMonth

Any references out there on how I can go about doing this? More of less this is what I want to do:

Value Expression:
[Measures].[Revenue] * (Distinct Number Of days)

Goal Expression:
10,000*[Distinct Number of Days)

Any suggestions of books to look for or good web resources would be much appreciated.

Thanks all

What period would you be calculating this over and have you considered how you want partial periods treated?

Is the KPI meant to be "adaptive"? So if the user selects a month, it calculates the average for that month and if they select a year it calculates the average for the year?

Assuming that your Time dimension has a calendar hierarchy and a Day attribute, you could do something like the following:

Count(descendants([Time].[Calendar].CurrentMember, [Time].[Calendar].[Day]))

If there is $30,000 revenue recorded on day 1 of the month, does that mean that the KPI has been met for the whole month?

|||Thanks for the reply Darren,

When you refer to [Time].[Calendar].[Day], does [Day] represent an ongoing incrementing day count from the start of dates kept? i.e. Not day or month, nor day of year?

The KPI is meant to be adaptive, at a later point I will go for fixed KPIS (e.g. yesterday).

If for example our Goal Value was $1000 a day, and we did $30,000 in day. Our KPI would be met for any 30 day span that held that date. So right now my datetime table looks like this:

Do you have any suggestions on books I buy for Analysis Services / MDX?

Thanks
|||

winnipeg wrote:

When you refer to [Time].[Calendar].[Day], does [Day] represent an ongoing incrementing day count from the start of dates kept? i.e. Not day or month, nor day of year?

No, the first parameter to the descendants function picks up the current context of the time.calendar hierarchy. If the current context of time.calendar is a month member, the descendants will be all the days in the month. If it is a year member, it will be all the days in the year

winnipeg wrote:


Do you have any suggestions on books I buy for Analysis Services / MDX?

MDX Solutions: With Microsoft SQL Server Analysis Services 2005 and Hyperion Essbase by George Spofford, Sivakumar Harinath, Christopher Webb, and Dylan Hai Huang - is the best one I know for MDX

Applied Microsoft Analysis Services 2005: And Microsoft Business Intelligence Platform by Teo Lachev - is a good alround SSAS book

sql

KPI - Sales Trend

Hi,

I am trying to create a Sales Trend KPI, where the value expression is last month sales (Identify last month based on current system date) and target expression is last month previous year sales amount times 1.04.

Is there a way to accomplish this using MDX in KPI.

Thanks,

Ravi

Identifying the lastest month of data is the trickiest part. One technique to do this is to create a calculated member named CurrentMonth that uses the VBA!Date() and VBA!DatePart() to construct a member reference that can then be resolved with StrToMember. Another techinique is to again create a CurrentMonth calculation with a hard coded reference to a date and then update the definition of this calculation each time a new month of data is loaded. (See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvbadev/html/pullingpiecesapart.asp for some help on the VBA functions.)

Once you have this CurrentMonth member, you can use the ParallelPeriod MDX function (http://msdn2.microsoft.com/en-us/library/ms145500(SQL.90).aspx) to calculate the lat month of the previous year.

|||Thanks Matt.

Monday, March 26, 2012

Kill Users Without Processadmin Role

Hi folks, i create a procedure in master db that kill users spids. Giving EXECUTE permission on the procedure to users without giving processadmin role doesn't work! Any guidelines?
Howdy!Other than "Don't do that", nope.

Killing processes requires a lot more understanding of the server than the average user is ever likely to have. Our tech support people always want that ability, but I've never found any remotely safe way to give it to them because they don't think in terms of the impact that killing a process might have.

-PatP|||Teacher, it's the same LOCKING issue; The WELL DESIGNED VB APPLICATION timesout often coz of a table exclusively locked by one of the user; if the DBA isn't available; what to do then. This is not the solution but at least it would help the users to proceed.
No doubt, It's coz of the poorly designed tables; but i can't change all just once!

Howdy!|||I'll conceed that this is drastic, but if you have to give them something to fix the problem without having someone technically competent (a dba) to resolve the underlying problems on duty, then the best answer I've found is to give two people permission to reboot the database server.

If the entire machine (therefore the SQL Server) goes down, all of the database connections will be dropped at once. The resulting rollbacks will be handled by the recovery process when the SQL Service restarts after the reboot.

The total impact of a reboot will be large, but it will still be smaller than the probable impact of killing arbitrary spids. This isn't a good solution, but it is the best one I can offer if you can't have a dba that understands the issues on hand to resolve these problems.

-PatP

Monday, March 12, 2012

Key cannot be null. Parameter name: key

We just upgraded to SS2005. After the upgrade, we can no longer create
subscriptions out of Execution Snapshot.
Try this experiment:
Create a report, with a simple SQL statement like "select * from CustomerDim
where CustomerPk = @.CustomerPk"
Go to Report Parameter, check the "Allow Null" box
Deploy the report
Go to the report on report server, render the report from Execution Snapshot
Now go to Subscription, and try to create a new subscription. The Parameter
CustomerPk will be grayed out, because of the Execution Snapshot
After you clicked OK, the subscription will return the error:
Key cannot be null. Parameter name: key
This error does not occur before the upgrade.
How can we create subscriptions out of Execution Snapshot in SS2005?
Thanks,
John WI've got the same problem. Did you find any solution?
Regards,
/Mattias
"LBJOHN" wrote:
> We just upgraded to SS2005. After the upgrade, we can no longer create
> subscriptions out of Execution Snapshot.
> Try this experiment:
> Create a report, with a simple SQL statement like "select * from CustomerDim
> where CustomerPk = @.CustomerPk"
> Go to Report Parameter, check the "Allow Null" box
> Deploy the report
> Go to the report on report server, render the report from Execution Snapshot
> Now go to Subscription, and try to create a new subscription. The Parameter
> CustomerPk will be grayed out, because of the Execution Snapshot
> After you clicked OK, the subscription will return the error:
> Key cannot be null. Parameter name: key
> This error does not occur before the upgrade.
> How can we create subscriptions out of Execution Snapshot in SS2005?
> Thanks,
> John W

Friday, March 9, 2012

Keeping track History Maintainance--Design Issue

Hi all,
i do have a new module named as Project Costing, in which i
have to create a Heirarchy of Activities,
Some thing of this sort
Project
|--Phase1
|--Stage1
|--Phase2
|--Stage2
This can go at any level, but In each stage i need to have to add
cost categories involved, which again constitutes to another eight
Tables excluding the top oNe which can be built with Two tables.
Problem
When ever i define a project it comes into an estimate Mode.
Then there is a seperate link For project update, I should not touch
what i have done in Project Estimate, because i need to compare what i
have done in Estimate and actuals,
do i have to replicate the same tables[ might involve atleast 10
tables] and do it or do i have to manage with the same table.
I can give you any sort of input for this
Thanks in advance
thomsonIf the hierarchy can have a fixed number of levels, consider designing a
regular relational model - physically with as many tables as there are level
s.
However, if your requirements suggest variable levels of hiearchy, consider
using a tree/hierarchy model. Google for "trees and hieararchies" or search
this news group for more info.
But rememer - an efficient hierarchy is based on a physical model that
prevents circular referencing. Which can be a b*tch. ;)
In both of the above models you have the option of storing multiple node
properties separately - e.g. costs, estimates, etc.
ML

Wednesday, March 7, 2012

Keep track changes made in data

I want to create a page(using GridView) where it will detect changes made in the database and display it for Administrator observation. I've created a table name history for this purpose.

History

guid (uniqueidentifier)

dateCreated(datetime)

lastDateUpdated(datetime)

changesMade(varchar(50)) -- eg; dropdownlist

oldValue(varchar(50)) -- compaq

newValue(varchar(50)) --dell

updateBy(varchar(10)) <-- username of registered user

comNo(int) = foreign key for Computer table

History data will insert data whenever a changes made. Could anyone advise and direct me how to do this function. I was thinking of using stored procedure to insert the data. Thanks in advance.

You can use a trigger in MSSQL to take action anytime a change to a row (insert, update, delete) takes place.

|||

I try to use trigger and get this error. Incorrect syntax near @.TEMP

This is the code

CREATE TRIGGERChangesTrigger

ONdbo.Computer

FOR UPDATE

AS

DECLARE@.TEMPAs varchar(50)

IF UPDATE(active)

BEGIN

SET@.TEMP ='active'

END

IF UPDATE(make)

BEGIN

SET@.TEMP ='make'

END

IF UPDATE(model)

BEGIN

SET@.TEMP ='model'

END

IF UPDATE(processor)

BEGIN

SET@.TEMP ='processor'

END

IF UPDATE(speed)

BEGIN

SET@.TEMP ='speed'

END

IF UPDATE(memory)

BEGIN

SET@.TEMP ='memory'

END

IF UPDATE(harddisk)

BEGIN

SET@.TEMP ='harddisk'

END

IF UPDATE(serialNo)

BEGIN

SET@.TEMP ='serialNo'

END

IF UPDATE(assetNo)

BEGIN

SET@.TEMP ='assetNo'

END

IF UPDATE(opsystem)

BEGIN

SET@.TEMP ='opSystem'

END

IF UPDATE(msOfficeVersion)

BEGIN

SET@.TEMP ='msOfficeVersion'

END

IF UPDATE(invoiceNo)

BEGIN

SET@.TEMP ='invoiceNo'

END

IF UPDATE(poNo)

BEGIN

SET@.TEMP ='poNo'

END

IF UPDATE(networkCard)

BEGIN

SET@.TEMP ='networkCard'

END

IF UPDATE(ipAddress)

BEGIN

SET@.TEMP ='ipAddress'

END

IF UPDATE(ras)

BEGIN

SET@.TEMP ='ras'

END

IF UPDATE(rasvpn)

BEGIN

SET@.TEMP ='rasvpn'

END

IF UPDATE(device)

BEGIN

SET@.TEMP ='device'

END

IF UPDATE(floppyDisk)

BEGIN

SET@.TEMP ='ROUTER_NAME'

END

IF UPDATE(userId)

BEGIN

SET@.TEMP ='ROUTER_NAME'

END

INSERT INTOHistory(lastDateUpdated, changesMade, oldValue, newValue, wscNo, updateBy)

VALUES(GETDATE(), @.TEMP, deleted.@.TEMP, inserted.@.TEMP, updated.wscNo,SUSER_SNAME())

Then I found out that SUSER_NAME doesn't insert the name of people who logged in and update the data.

|||Why do you usedeleted.@.TEMP/inserted.@.TEMP ? @.TEMP is a variable, not a column in the table. If you want to insert into History table with values from different columns in deleted/inserted table, you need different INSERT command for each case (for different updated columns).|||

Or we can make a trick by using COLUMNS_UPDATED() function and EXECUTE dynamic SQL statement in the trigger. Suppose the dbo.Computer table looks like:

dbo.Computer (ComID,active,make,model,processor,speed,memory,harddisk,serialNo,assetNo,
opSystem,msOfficeVersion,invoiceNo,poNo,networkCard,ipAddress,ras,rasvpn)

Then we can use such a trigger:


ALTER TRIGGER ChangesTrigger ON dbo.Computer FOR UPDATE
AS
DECLARE @.TEMP As varchar(50)
SELECT @.TEMP=CASE WHEN COLUMNS_UPDATED()&2=2
THEN 'active'
WHEN COLUMNS_UPDATED()&4=4
THEN 'make'
WHEN COLUMNS_UPDATED()&8=8
THEN 'model'
WHEN COLUMNS_UPDATED()&16=16
THEN 'processor'
--<add other conditions here...>
WHEN COLUMNS_UPDATED()&power(2,20-1)=power(2,20-1)
THEN 'ROUTER_NAME'
WHEN COLUMNS_UPDATED()&power(2,21-1)=power(2,21-1)
THEN 'ROUTER_NAME'
END

EXEC('INSERT INTO History(lastDateUpdated, changesMade, oldValue, newValue, wscNo, updateBy)
VALUES(GETDATE(),'''+@.TEMP+''',deleted.['+@.TEMP+'],inserted.['+@.TEMP+'], updated.wscNo, SUSER_SNAME())')

go

For more information about COLUMNS_UPDATED function, you can refer to:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_create2_7eeq.asp

|||

I got a new idea: if update to the dbo.Computer table will always effect only 1 column, we can get the value of @.Temp (that's the effected column name, right?) directly from system table:


ALTER trigger trg_test on tblTrg for update
as
declare @.temp sysname
SELECT @.temp=name FROM syscolumns
WHERE id=OBJECT_ID('tblTrg') and POWER(2,colid-1)=COLUMNS_UPDATED()
EXEC('INSERT INTO History(lastDateUpdated, changesMade, oldValue, newValue, wscNo, updateBy)
VALUES(GETDATE(),'''+@.TEMP+''',deleted.['+@.TEMP+'],inserted.['+@.TEMP+'], updated.wscNo, SUSER_SNAME())')
go

|||What is the numbers anyway and how to use it. Anyway, I never use trigger and stored procedure before so I don't know the command that can be used in trigger. After all, the code that i use for trigger was taken from other sources and i modify according to my database. thanks for direction. i will try the codes.|||

This is the error I get.

The name "deleted.serialNo" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.

This is the trigger I wrote since I'm confuse with the use of power(2,20-1). What is wrong with the code. I change updated.wscNo to inserted.wscNo since wscNo couldn,t be updated and I actually don't know what should i put in inserted.wscNo because I want to catch the no of computer that changes are made.

ALTER TRIGGER

ChangesTriggerONdbo.ComputerFOR UPDATE

AS

DECLARE

@.TEMPAs varchar(50)

SELECT

@.TEMP=CASE WHEN COLUMNS_UPDATED()&2=2THEN'active'WHEN COLUMNS_UPDATED()&4=4THEN'make'WHEN COLUMNS_UPDATED()&8=8THEN'model'WHEN COLUMNS_UPDATED()&16=16THEN'processor'WHEN COLUMNS_UPDATED()&32=32THEN'speed'WHEN COLUMNS_UPDATED()&64=64THEN'memory'WHEN COLUMNS_UPDATED()&128=128THEN'harddisk'WHEN COLUMNS_UPDATED()&256=256THEN'serialNo'WHEN COLUMNS_UPDATED()&512=512THEN'assetNo'WHEN COLUMNS_UPDATED()&1024=1024THEN'opSystem'WHEN COLUMNS_UPDATED()&2048=2048THEN'version'WHEN COLUMNS_UPDATED()&4096=4096THEN'opSerial'WHEN COLUMNS_UPDATED()&8192=8192THEN'msOfficeVersion'WHEN COLUMNS_UPDATED()&16384=16384THEN'invoiceNo'WHEN COLUMNS_UPDATED()&32768=32768THEN'poNo'WHEN COLUMNS_UPDATED()&65536=65536THEN'networkCard'WHEN COLUMNS_UPDATED()&131072=131072THEN'ipAddress'WHEN COLUMNS_UPDATED()&262144=262144THEN'ras'WHEN COLUMNS_UPDATED()&524288=524288THEN'rasvpn'WHEN COLUMNS_UPDATED()&1048576=1048576THEN'device'WHEN COLUMNS_UPDATED()&2097152=2097152THEN'floppyDisk'WHEN COLUMNS_UPDATED()&4194304=4194304THEN'userId'ENDEXEC('INSERT INTO History(lastDateUpdated, changesMade, oldValue, newValue, wscNo, updateBy)VALUES(GETDATE(), '''+@.TEMP+''', deleted.['+@.TEMP+'], inserted.['+@.TEMP+'], inserted.wscNo, SUSER_SNAME())')

I delete go because I got an error regarding go.

|||

deleted and inserted aren't available in that context (EXEC) because it's technically not executing within the context of the trigger any longer. Also INSERT INTO ... VALUES would be the wrong syntax for accessing deleted and inserted pseudo tables. You would need an INSERT ... SELECT. The trigger would also fail if you modified multiple columns (Only recording a single change), or multiple rows (possibly, depends on how you fix the problems), and logging changes that don't really happen (UPDATE table SET col=col) would show records being changed that don't get changed.

You would need to do something like:

DECLARE@.TEMP varchar(50)

DECLARE @.oldval varchar(50)

DECLARE @.newval varchar(50)

IF COLUMNS_UPDATED()&2=2 SELECT @.TEMP='active',@.oldval=deleted.active,@.newval=deleted.active FROM inserted JOIN deleted ON inserted.wsc=deleted.wsc

...

and at then reference @.oldval and @.newval instead of inserted/deleted pseudo tables, but that still has the multiple columns and multiple row update problems.

However, I would suggest a change in approach, which works much better. Design a standard audit table like:

AuditID identity int

ChangeType char(1) ' I/U/D

ChangeDate datetime default getdate()

(a column here for each column in your table with same column definiation - with the exception that all columns are nullable)

The create your triggers like:

ON INSERT:

INSERT INTO History(ChangeType,...) SELECT 'I',I.* FROM inserted

ON UPDATE:

INSERT INTO History(ChangeType,...) SELECT 'U',I.* FROM inserted i ' Optionally add JOIN deleted d WHERE (i.col1<>d.col1 OR (i.col1 IS NULL AND d.col1 IS NOT NULL) OR (i.col1 IS NOT NULL AND d.col1 IS NULL)) and repeat for each column to remove false change entries

ON DELETE:

INSERT INTO History(ChangeType,wscNo) SELECT 'D',deleted.wscNo FROM deleted

Then you can track every change to every column, including the cases where multiple columns (or records) are updated at a time. Although, it does make the logic for displaying what was changed a bit more difficult, it's not that complicated, and history tracking usually isn't done that often in most cases. This is also a pretty common audit table, so it can carry over from table to table and project to project. (Most people would call this table something like AuditComputers, where Computers is the original table).

You will have the problem where SUSER_SNAME won't give you the name of the person who did the change, unless you create a SQL user for each person that is allowed to make changes, and each connection by those users are done with their own credentials, but that's a different issue. If you need to propegate actual user information from asp.net where they don't log in to sql server with their own identity, then it gets a bit more tricky. You can still do it (Mostly) with triggers, if you define an UpdatedBy column in the original table. You can also enforce specific rules within the insert/update triggers to make sure it's being filled LIKE:

IF NOT UPDATED(UpdatedBy) BEGIN RAISEERROR('You must supply the UpdatedBy column when modifying records') ROLLBACK END ELSE BEGIN ... END

Deleted entries are a bit more tricky because you don't have the user information in any of the information available to the trigger when it happens. In that case, you may want to make a stored procedure to deleted records from the table, and insert the data into the audit table within that. Then remove access to delete from the table directly through permissions.

|||

This is the code I made. I got an error between END and ON. I think it require me to put some code but i don't know what it is.

CREATE TRIGGERChangedTrigger

ONdbo.Computer

FOR UPDATE

AS

DECLARE

@.changeTypechar(1),

@.guiduniqueidentifier,

@.dateCreateddatetime,

@.lastDateUpdateddatetime,

@.changesMadevarchar(50),

@.oldValuevarchar(50),

@.newValuevarchar(50),

@.wscNobigint,

@.updateByvarchar(10)

ON INSERT:

BEGIN

INSERT INTOHistory(guid,changeType,dateCreated,lastDateUpdated,changesMade,oldValue,newValue,wscNo,updateBy)

VALUES(@.guid,'I',GETDATE(),GETDATE(),@.changesMade,@.oldValue,@.newValue,@.wscNo,SUSER_NAME())

SELECT'I', I.*FROMinserted

END

ON UPDATE:

BEGIN

INSERT INTOHistory(guid,changeType,lastDateUpdated,changesMade,oldValue,newValue,wscNo,updateBy)

VALUES(@.guid,'U',GETDATE(),@.changesMade,@.oldValue,@.newValue,@.wscNo,SUSER_NAME())

SELECT'U', I.*FROMinserted iJOINdeleted d

END

ON DELETE:

BEGIN

INSERT INTOHistory(guid,changeType,wscNo)VALUES(@.guid,'D',@.wscNo)

SELECT'D', deleted.wscNoFROMdeleted

END

|||Sorry, the ON INSERT: wasn't a T-SQL command. The On insert would look like:

CREATE TRIGGERComputer_Inserted

ONdbo.Computer

FOR INSERT

AS

BEGIN

INSERT INTOHistory(changeType,{List each column in the Computer Table here})

SELECT'I', i.*FROMinserted i

END

THe update portion would be:

CREATE TRIGGERComputer_Updated

ONdbo.Computer

FOR UPDATE

AS

BEGIN

INSERT INTOHistory(changeType,{List each column in the Computer Table here})

SELECT'U', i.*FROMinserted i

END

And the deleted trigger would be:

CREATE TRIGGERComputer_Updated

ONdbo.Computer

FOR DELETE

AS

BEGIN

INSERT INTOHistory(ChangeType,wscNo)

SELECT'D', deleted.wscNoFROMdeleted

END

|||

Owh! It should be separated. Okay I'll try and let u know if any problem occur.

|||

I got this error for insert and update trigger. 'Incorrect syntax near {'

Update:

ALTER TRIGGERInsertTrigger

ONdbo.Computer

FOR INSERT

AS

BEGIN

INSERT INTOHistory(changeType,{wscNo,active,make,model,processor,speed,memory,harddisk,serialNo,assetNo,opSystem,version,opSerial,msOfficeVersion,invoiceNo,poNo,networkCard,ipAddress,ras,rasvpn,device,floppyDisk,userId})

SELECT'I', i.*FROMinserted i

END

Insert:

ALTER TRIGGERUpdateTrigger

ONdbo.Computer

FOR UPDATE

AS

BEGIN

INSERT INTOHistory(changeType,{wscNo,active,make,model,processor,speed,memory,harddisk,serialNo,assetNo,opSystem,version,opSerial,msOfficeVersion,invoiceNo,poNo,networkCard,ipAddress,ras,rasvpn,device,floppyDisk,userId})

SELECT'U', i.*FROMinserted i

END

If I remove {} the error says that all the computer table column is not exist

|||remove the {}'s and make sure your History table also has those columns (wscNo,active,make,model, etc)|||Oh, I have to include the computer table attribute in it. Is there any other way, let's say like History table i've created, i make wscNo(primary key for tabel Computer) as a foreign key.

Friday, February 24, 2012

Keep only X # of backups when appending to BU file

Using SQL Server 2005 STD, is there a way to create a maintance plan to
backup the database, appending to a file, but only keeping the last X number
of backups?
I would like to keep 4 full backups at a time. When the 5th backup occurs, I
would like the first to be deleted.
I've seen options like this in 3rd party backup tools, but is there a way to
do this natively w/ SQL Server?
Have a look at the expire parameter of the backup command. From
http://msdn2.microsoft.com/en-us/library/ms187510.aspx
a.. To have the backup set expire after a specific number of days, click
After (the default option), and enter the number of days after set creation
that the set will expire. This value can be from 0 to 99999 days; a value of
0 days means that the backup set will never expire.
The default value is set in the Default backup media retention (in days)
option of the Server Properties dialog box (Database Settings Page). To
access this, right-click the server name in Object Explorer and select
properties; then select the Database Settings page.
Hilary Cotter
Director of Text Mining and Database Strategy
RelevantNOISE.Com - Dedicated to mining blogs for business intelligence.
This posting is my own and doesn't necessarily represent RelevantNoise's
positions, strategies or opinions.
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Dan" <Dan@.discussions.microsoft.com> wrote in message
news:DEA2E6D1-DB67-42F7-8406-E37EB553AEA9@.microsoft.com...
> Using SQL Server 2005 STD, is there a way to create a maintance plan to
> backup the database, appending to a file, but only keeping the last X
> number
> of backups?
> I would like to keep 4 full backups at a time. When the 5th backup occurs,
> I
> would like the first to be deleted.
> I've seen options like this in 3rd party backup tools, but is there a way
> to
> do this natively w/ SQL Server?
|||If every backup goes to the same file, then the answer is no. There
is no way for SQL Server to drop old backups from the front of the
file. The solution is for each backup to go to an individual file.
Roy Harvey
Beacon Falls, CT
On Tue, 19 Sep 2006 18:34:01 -0700, Dan
<Dan@.discussions.microsoft.com> wrote:

>Using SQL Server 2005 STD, is there a way to create a maintance plan to
>backup the database, appending to a file, but only keeping the last X number
>of backups?
>I would like to keep 4 full backups at a time. When the 5th backup occurs, I
>would like the first to be deleted.
>I've seen options like this in 3rd party backup tools, but is there a way to
>do this natively w/ SQL Server?

Keep only X # of backups when appending to BU file

Using SQL Server 2005 STD, is there a way to create a maintance plan to
backup the database, appending to a file, but only keeping the last X number
of backups?
I would like to keep 4 full backups at a time. When the 5th backup occurs, I
would like the first to be deleted.
I've seen options like this in 3rd party backup tools, but is there a way to
do this natively w/ SQL Server?Have a look at the expire parameter of the backup command. From
http://msdn2.microsoft.com/en-us/library/ms187510.aspx
a.. To have the backup set expire after a specific number of days, click
After (the default option), and enter the number of days after set creation
that the set will expire. This value can be from 0 to 99999 days; a value of
0 days means that the backup set will never expire.
The default value is set in the Default backup media retention (in days)
option of the Server Properties dialog box (Database Settings Page). To
access this, right-click the server name in Object Explorer and select
properties; then select the Database Settings page.
Hilary Cotter
Director of Text Mining and Database Strategy
RelevantNOISE.Com - Dedicated to mining blogs for business intelligence.
This posting is my own and doesn't necessarily represent RelevantNoise's
positions, strategies or opinions.
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Dan" <Dan@.discussions.microsoft.com> wrote in message
news:DEA2E6D1-DB67-42F7-8406-E37EB553AEA9@.microsoft.com...
> Using SQL Server 2005 STD, is there a way to create a maintance plan to
> backup the database, appending to a file, but only keeping the last X
> number
> of backups?
> I would like to keep 4 full backups at a time. When the 5th backup occurs,
> I
> would like the first to be deleted.
> I've seen options like this in 3rd party backup tools, but is there a way
> to
> do this natively w/ SQL Server?|||If every backup goes to the same file, then the answer is no. There
is no way for SQL Server to drop old backups from the front of the
file. The solution is for each backup to go to an individual file.
Roy Harvey
Beacon Falls, CT
On Tue, 19 Sep 2006 18:34:01 -0700, Dan
<Dan@.discussions.microsoft.com> wrote:

>Using SQL Server 2005 STD, is there a way to create a maintance plan to
>backup the database, appending to a file, but only keeping the last X numbe
r
>of backups?
>I would like to keep 4 full backups at a time. When the 5th backup occurs,
I
>would like the first to be deleted.
>I've seen options like this in 3rd party backup tools, but is there a way t
o
>do this natively w/ SQL Server?

Keep only X # of backups when appending to BU file

Using SQL Server 2005 STD, is there a way to create a maintance plan to
backup the database, appending to a file, but only keeping the last X number
of backups?
I would like to keep 4 full backups at a time. When the 5th backup occurs, I
would like the first to be deleted.
I've seen options like this in 3rd party backup tools, but is there a way to
do this natively w/ SQL Server?Have a look at the expire parameter of the backup command. From
http://msdn2.microsoft.com/en-us/library/ms187510.aspx
a.. To have the backup set expire after a specific number of days, click
After (the default option), and enter the number of days after set creation
that the set will expire. This value can be from 0 to 99999 days; a value of
0 days means that the backup set will never expire.
The default value is set in the Default backup media retention (in days)
option of the Server Properties dialog box (Database Settings Page). To
access this, right-click the server name in Object Explorer and select
properties; then select the Database Settings page.
Hilary Cotter
Director of Text Mining and Database Strategy
RelevantNOISE.Com - Dedicated to mining blogs for business intelligence.
This posting is my own and doesn't necessarily represent RelevantNoise's
positions, strategies or opinions.
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Dan" <Dan@.discussions.microsoft.com> wrote in message
news:DEA2E6D1-DB67-42F7-8406-E37EB553AEA9@.microsoft.com...
> Using SQL Server 2005 STD, is there a way to create a maintance plan to
> backup the database, appending to a file, but only keeping the last X
> number
> of backups?
> I would like to keep 4 full backups at a time. When the 5th backup occurs,
> I
> would like the first to be deleted.
> I've seen options like this in 3rd party backup tools, but is there a way
> to
> do this natively w/ SQL Server?|||If every backup goes to the same file, then the answer is no. There
is no way for SQL Server to drop old backups from the front of the
file. The solution is for each backup to go to an individual file.
Roy Harvey
Beacon Falls, CT
On Tue, 19 Sep 2006 18:34:01 -0700, Dan
<Dan@.discussions.microsoft.com> wrote:
>Using SQL Server 2005 STD, is there a way to create a maintance plan to
>backup the database, appending to a file, but only keeping the last X number
>of backups?
>I would like to keep 4 full backups at a time. When the 5th backup occurs, I
>would like the first to be deleted.
>I've seen options like this in 3rd party backup tools, but is there a way to
>do this natively w/ SQL Server?

Keep existing object unchanged or Create Schema at subscriber =false?

Hi,

I have the same database(3GB) in 2 physical locations in usa and europe

I need to create a publisher and subscriber between these 2 database without sending any snapshot because i have the same data in the 2 sides, is it possible ?

Thx

Jim

Yes it's possible. When you add a subscription through sp_addsubscription for transactinal publication, you can specify that the subscriber already has the schema and initial data by specify @.sync_type='none' or 'replication support only', for merge (sp_addmergepublication), you can specify @.sync_type='none'

Transactional publication:

[ @.sync_type=] 'sync_type'

replication support only
Provides automatic generation at the Subscriber of article custom stored procedures and triggers that support updating subscriptions. Assumes that Subscriber already has the schema and initial data for published tables. When configuring a peer-to-peer transactional replication topology, ensure that the data at all nodes in the topology is identical. Quiesce the replication topology before configuring peer-to-peer transactional replication using this option. For more information, see How to: Quiesce a Replication Topology (Replication Transact-SQL Programming).

Merge:

[ @.sync_type=] 'sync_type'

Is the subscription synchronization type. sync_type is nvarchar(15), with a default of automatic. Can be automatic or none. If automatic, the schema and initial data for published tables are transferred to the Subscriber first. If none, it is assumed the Subscriber already has the schema and initial data for published tables. System tables and data are always transferred.

for more information, see SQL Server 2005 books online:

http://msdn2.microsoft.com/en-us/library/ms181702.aspx

http://msdn2.microsoft.com/en-us/library/ms187717.aspx

Thanks,

Zhiqiang Feng

|||

Hi,

i did what you said above but i ve got the following error while synchronization on the subscriber:

{call sp_MSsetconflicttable (N'Customer', N'MSmerge_conflict_testwithoutsnap_Customer', N'myserver', N'testwithoutsnapshot', N'testwithoutsnap')}

merge publication for customer table:

-- Enabling the replication database
use master
exec sp_replicationdboption @.dbname = N'testwithoutsnapshot', @.optname = N'merge publish', @.value = N'true'
GO

-- Adding the merge publication
use [testwithoutsnapshot]
exec sp_addmergepublication @.publication = N'testwithoutsnap', @.description = N'Merge publication of database ''testwithoutsnapshot'' from Publisher ''myserver''.', @.sync_mode = N'native', @.retention = 14, @.allow_push = N'true', @.allow_pull = N'true', @.allow_anonymous = N'true', @.enabled_for_internet = N'false', @.snapshot_in_defaultfolder = N'true', @.compress_snapshot = N'false', @.ftp_port = 21, @.ftp_login = N'anonymous', @.allow_subscription_copy = N'false', @.add_to_active_directory = N'false', @.dynamic_filters = N'false', @.conflict_retention = 14, @.keep_partition_changes = N'false', @.allow_synctoalternate = N'false', @.max_concurrent_merge = 0, @.max_concurrent_dynamic_snapshots = 0, @.use_partition_groups = N'false', @.publication_compatibility_level = N'90RTM', @.replicate_ddl = 1, @.allow_subscriber_initiated_snapshot = N'false', @.allow_web_synchronization = N'false', @.allow_partition_realignment = N'true', @.retention_period_unit = N'days', @.conflict_logging = N'both', @.automatic_reinitialization_policy = 0
GO


exec sp_addpublication_snapshot @.publication = N'testwithoutsnap', @.frequency_type = 1, @.frequency_interval = 0, @.frequency_relative_interval = 0, @.frequency_recurrence_factor = 0, @.frequency_subday = 0, @.frequency_subday_interval = 0, @.active_start_time_of_day = 500, @.active_end_time_of_day = 235959, @.active_start_date = 0, @.active_end_date = 0, @.job_login = null, @.job_password = null, @.publisher_security_mode = 1
exec sp_grant_publication_access @.publication = N'testwithoutsnap', @.login = N'sa'
GO
exec sp_grant_publication_access @.publication = N'testwithoutsnap', @.login = N'NT AUTHORITY\SYSTEM'
GO
exec sp_grant_publication_access @.publication = N'testwithoutsnap', @.login = N'BUILTIN\Administrators'
GO
exec sp_grant_publication_access @.publication = N'testwithoutsnap', @.login = N'myserver\SQLServer2005SQLAgentUser$myserver$MSSQLSERVER'
GO
exec sp_grant_publication_access @.publication = N'testwithoutsnap', @.login = N'myserver\SQLServer2005MSSQLUser$myserver$MSSQLSERVER'
GO
exec sp_grant_publication_access @.publication = N'testwithoutsnap', @.login = N'distributor_admin'
GO

-- Adding the merge articles
use [testwithoutsnapshot]
exec sp_addmergearticle @.publication = N'testwithoutsnap', @.article = N'Customer', @.source_owner = N'dbo', @.source_object = N'Customer', @.type = N'table', @.description = N'', @.creation_script = N'', @.pre_creation_cmd = N'none', @.schema_option = 0x0000000004034FD1, @.identityrangemanagementoption = N'none', @.destination_owner = N'dbo', @.force_reinit_subscription = 1, @.column_tracking = N'false', @.subset_filterclause = N'', @.vertical_partition = N'false', @.verify_resolver_signature = 1, @.allow_interactive_resolver = N'false', @.fast_multicol_updateproc = N'true', @.check_permissions = 0, @.subscriber_upload_options = 0, @.delete_tracking = N'true', @.compensate_for_errors = N'false', @.stream_blob_columns = N'false', @.partition_options = 0
GO

use [testwithoutsnapshot]
exec sp_changemergepublication N'testwithoutsnap', N'status', N'active'
GO
-- Adding the merge subscriptions
use [testwithoutsnapshot]
exec sp_addmergesubscription @.publication = N'testwithoutsnap', @.subscriber = N'myserver', @.subscriber_db = N'testwithoutsnapshot1', @.subscription_type = N'Pull', @.sync_type = N'None', @.subscriber_type = N'Local', @.subscription_priority = 0, @.description = N'', @.use_interactive_resolver = N'False'
GO

for publication articel i used "Keep existing object unchanged" and create schema at subscriber =false

any suggestion?

Thx

Jim

|||

Hi,

any help?

I am still waiting ?

Regards,

Jim

|||

Do you already have a guidcol in your publishing table and subscriber table? If not, how did you add it? The guidcol column value need to be exactly the same on publisher and subscriber table.

Did you run snapshot agent before merge agent?

I was playing with your script yesterday but hit some issues, I will let your know the outcome today.

Thanks,

Zhiqiang Feng

|||

If you don't have a rowguidcol column already on both side of your tables with identical column values, the recommend way is to add it on source db, then backup and restore the db to the destination server. Then from there you can setup no-sync merge replication between the 2 sites.

Or, you could add a new rowguidcol on source table, and find a way to just delivery the value of this new column to the destination table, this way you will avoid the overhead of delivering all 3GB data.

Thanks,

Zhiqiang Feng

|||

Thanks for you patience, I hit a similar error as you encountered. Will dig into it further tomorrow.

Zhiqiang Feng

|||

Hi,

Thx for your reply, i made a publication and i added a rowguid with null option in target data (with or without update rowguid from source DB) and later on a created the subscription , and the system gave me the same error (i can\t make backup on source db because because i can't send any data or any snapshot)

Any other idea ?

Regards,

Jim

|||

Hi, Jim,

I think I know what happened, when you use alter table to add a rowguid column, did you add the rowguidcol property to the column? ROWGUIDCOL property is required by merge replication. And if you don't have rowguidcol property for the rowguid column on the destination table, merge replication will not work, of course, we should give a better error message instead of the weird sp_MSsetconflicttable error.

For example, you can use following statement to add rowguid column with rowguidcol property

alter table mytable add ourguid uniqueidentifier default newid() rowguidcol

Let me know if that's the problem you're encountering.

Of course, once you correct this, the other thing is to make sure you have the exact same rowguid column value on both source table and target table before setting up replication.Thanks,

Zhiqiang Feng

|||

The other solution to your case is to actually use normal merge publication, when you create a snapshot at publisher, you can specify to have the snapshot compressed to a local cab file, then copy this cab file to the other location (Europe in your case, or burn a DVD and deliver the DVD to Europe site), when you run merge agent at the subscriber for the first time, you could use the merge agent parameter -AltSnapshotFolder to specify the local copy snapshot cab file in Europe, this way the 3GB data is not replicated through wire instead it's on local network. This is recommended approach as there are several known issues in SQL 2005 for merge nosync replication and you don't want to hit them later on.

Thanks,

Zhiqiang Feng

|||

hi Zhiqiang,

I tried this one: alter table mytable add ourguid uniqueidentifier default newid() rowguidcol


and it worked fine but you need to replace the empty "ourguid" filed in subscriber side from publisher side before adding rowguidcol property on the field.

but i have more than 400 table and i need to replace their related rowguidcol from publisher table, very hard way.

about your last post , i know about it but i don't need to send anything between 2 physical location.

Regards,

Jim