Monday, March 19, 2012
calling a User Defined Function in transactional replication
tried a horizontal filter to get rows to replicate but that isn't working
very well.
FYI the makeup of the replication is this: aproximately 20
Publisher/Distributors and 1 central subscriber. All the remote servers use
transactional replication to send the subscriber. The horizontal filter
reduces the number of records but it sometimes does not send all the rows to
the subscriber. Once the repliaction fails to deliver all the rows (usually
after a day or so ) the missing rows are never replicated back.
here is an example - first a udf
CREATE FUNCTION test(@.state char(2))
RETURNS @.retauthors table (au_id char(11))
AS
BEGIN
INSERT INTO @.retauthors
SELECT DISTINCT authors.au_id FROM authors, titleauthor,
(SELECT au_id, test=COUNT(au_id) FROM titleauthor GROUP
BY au_id HAVING COUNT(au_id)>1) AS a
WHERE authors.au_id=titleauthor.au_id
AND a.test>1
AND authors.au_id=a.au_id
AND authors.state=@.state
AND titleauthor.au_id=a.au_id
RETURN
END
SELECT * FROM dbo.authors_filter('CA')
and here is an example of its usage in a filter
WHERE au_id IN (SELECT au_id FROM dbo.Authors_Filter('CA'))
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
"LP" <LP@.discussions.microsoft.com> wrote in message
news:F0027B50-1CF0-4E08-929C-662B60B2CAB2@.microsoft.com...
> How do I call a user defined function in a transactional replication.
I've
> tried a horizontal filter to get rows to replicate but that isn't working
> very well.
>
> FYI the makeup of the replication is this: aproximately 20
> Publisher/Distributors and 1 central subscriber. All the remote servers
use
> transactional replication to send the subscriber. The horizontal filter
> reduces the number of records but it sometimes does not send all the rows
to
> the subscriber. Once the repliaction fails to deliver all the rows
(usually
> after a day or so ) the missing rows are never replicated back.
Friday, February 24, 2012
Calendar is only one.
Thursday, February 16, 2012
Calculating Yield
possible judgements, GOOD and BAD.
I can filter the data to include just 1 month data, for example, Feb's data
from 02/01/06 to 02/28/06.
I would like to get output that looks like the following:
DATE YIELD
1 .90
2 .98
3 .80
4 .79
5 .60
6 1.00
...
The yield is calculated for each day as Total of (GOOD+BAD) / BAD
I'm looking to use a Stored Procedure that I pass the start and end date to
it.
Whats the best way to go about get the result set back?
BartDo you mean yield is GOOD / (GOOD + BAD)? (GOOD+BAD) / BAD will always
result in yields > 1.
I think this will provide the result you requested:
create table #Judgement(JudgementDate datetime, Judgement varchar(4))
insert #Judgement values ('01 Feb 2006', 'GOOD')
insert #Judgement values ('01 Feb 2006', 'GOOD')
insert #Judgement values ('01 Feb 2006', 'GOOD')
insert #Judgement values ('01 Feb 2006', 'BAD')
insert #Judgement values ('01 Feb 2006', 'GOOD')
insert #Judgement values ('02 Feb 2006', 'GOOD')
insert #Judgement values ('02 Feb 2006', 'BAD')
insert #Judgement values ('02 Feb 2006', 'BAD')
insert #Judgement values ('03 Feb 2006', 'GOOD')
insert #Judgement values ('03 Feb 2006', 'GOOD')
insert #Judgement values ('03 Feb 2006', 'BAD')
insert #Judgement values ('03 Feb 2006', 'BAD')
insert #Judgement values ('04 Feb 2006', 'BAD')
go
create procedure getYield
@.start datetime,
@.end datetime
as
select JudgementDate, convert(decimal(9,2), count(*)) /
convert(decimal(9,2),sum(case when Judgement = 'BAD' then 1 else 0
end))
from #Judgement
where JudgementDate between @.start and @.end
group by JudgementDate
go
exec getYield '01 Feb 2006', '03 Feb 2006'|||You are correct, i was thinking the correct equation, but I typed the wrong
one.
Anyway, I was looking over your sugestion and I undertand now. However, if
there was
no data for a particular day, wouldn't that result in a 'Divide By Zero"
error?
Bart
"JeffB" <jeff.bolton@.citigatehudson.com> wrote in message
news:1142032601.550114.125100@.i39g2000cwa.googlegroups.com...
> Do you mean yield is GOOD / (GOOD + BAD)? (GOOD+BAD) / BAD will always
> result in yields > 1.
> I think this will provide the result you requested:
> create table #Judgement(JudgementDate datetime, Judgement varchar(4))
> insert #Judgement values ('01 Feb 2006', 'GOOD')
> insert #Judgement values ('01 Feb 2006', 'GOOD')
> insert #Judgement values ('01 Feb 2006', 'GOOD')
> insert #Judgement values ('01 Feb 2006', 'BAD')
> insert #Judgement values ('01 Feb 2006', 'GOOD')
> insert #Judgement values ('02 Feb 2006', 'GOOD')
> insert #Judgement values ('02 Feb 2006', 'BAD')
> insert #Judgement values ('02 Feb 2006', 'BAD')
> insert #Judgement values ('03 Feb 2006', 'GOOD')
> insert #Judgement values ('03 Feb 2006', 'GOOD')
> insert #Judgement values ('03 Feb 2006', 'BAD')
> insert #Judgement values ('03 Feb 2006', 'BAD')
> insert #Judgement values ('04 Feb 2006', 'BAD')
> go
> create procedure getYield
> @.start datetime,
> @.end datetime
> as
> select JudgementDate, convert(decimal(9,2), count(*)) /
> convert(decimal(9,2),sum(case when Judgement = 'BAD' then 1 else 0
> end))
> from #Judgement
> where JudgementDate between @.start and @.end
> group by JudgementDate
> go
> exec getYield '01 Feb 2006', '03 Feb 2006'
>|||Sorry, I didn't mean when the Date was missing, I meant when the denominator
was 0.
"JeffB" <jeff.bolton@.citigatehudson.com> wrote in message
news:1142032601.550114.125100@.i39g2000cwa.googlegroups.com...
> Do you mean yield is GOOD / (GOOD + BAD)? (GOOD+BAD) / BAD will always
> result in yields > 1.
> I think this will provide the result you requested:
> create table #Judgement(JudgementDate datetime, Judgement varchar(4))
> insert #Judgement values ('01 Feb 2006', 'GOOD')
> insert #Judgement values ('01 Feb 2006', 'GOOD')
> insert #Judgement values ('01 Feb 2006', 'GOOD')
> insert #Judgement values ('01 Feb 2006', 'BAD')
> insert #Judgement values ('01 Feb 2006', 'GOOD')
> insert #Judgement values ('02 Feb 2006', 'GOOD')
> insert #Judgement values ('02 Feb 2006', 'BAD')
> insert #Judgement values ('02 Feb 2006', 'BAD')
> insert #Judgement values ('03 Feb 2006', 'GOOD')
> insert #Judgement values ('03 Feb 2006', 'GOOD')
> insert #Judgement values ('03 Feb 2006', 'BAD')
> insert #Judgement values ('03 Feb 2006', 'BAD')
> insert #Judgement values ('04 Feb 2006', 'BAD')
> go
> create procedure getYield
> @.start datetime,
> @.end datetime
> as
> select JudgementDate, convert(decimal(9,2), count(*)) /
> convert(decimal(9,2),sum(case when Judgement = 'BAD' then 1 else 0
> end))
> from #Judgement
> where JudgementDate between @.start and @.end
> group by JudgementDate
> go
> exec getYield '01 Feb 2006', '03 Feb 2006'
>|||Using the "GOOD / (GOOD + BAD)" formula, the denominator will never be
0 because you are only looking in the Judgement table. If you were to
join to some date table in an outer join then you would do some
COALESCE on the calculations. Here is the revised format that joins to
a date table to account for missing dates:
drop table #Judgement
go
create table #Judgement(JudgementDate datetime, Judgement varchar(4))
insert #Judgement values ('01 Feb 2006', 'GOOD')
insert #Judgement values ('01 Feb 2006', 'GOOD')
insert #Judgement values ('01 Feb 2006', 'GOOD')
insert #Judgement values ('01 Feb 2006', 'BAD')
insert #Judgement values ('01 Feb 2006', 'GOOD')
insert #Judgement values ('02 Feb 2006', 'GOOD')
insert #Judgement values ('02 Feb 2006', 'BAD')
insert #Judgement values ('02 Feb 2006', 'BAD')
insert #Judgement values ('03 Feb 2006', 'GOOD')
insert #Judgement values ('03 Feb 2006', 'GOOD')
insert #Judgement values ('03 Feb 2006', 'BAD')
insert #Judgement values ('03 Feb 2006', 'BAD')
insert #Judgement values ('04 Feb 2006', 'BAD')
insert #Judgement values ('05 Feb 2006', 'GOOD')
go
drop table #Date
go
create table #Date([Date] datetime)
insert #Date values ('01 Feb 2006')
insert #Date values ('02 Feb 2006')
insert #Date values ('03 Feb 2006')
insert #Date values ('03 Feb 2006')
insert #Date values ('04 Feb 2006')
insert #Date values ('05 Feb 2006')
insert #Date values ('06 Feb 2006')
insert #Date values ('07 Feb 2006')
go
drop procedure getYield
go
create procedure getYield
@.start datetime,
@.end datetime
as
select JudgementDate, case when denominator = 0 then 0 else
convert(decimal(9,2), numerator) / convert(decimal(9,2), denominator)
end
from (select dt.[Date] JudgementDate, sum(case when Judgement = 'GOOD'
then 1 else 0 end) numerator, count(*) denominator
from #Date dt
left outer join #Judgement j
on dt.[Date] = j.JudgementDate
where dt.[Date] between @.start and @.end
group by dt.[Date]) x
go
exec getYield '01 Feb 2006', '07 Feb 2006'
Friday, February 10, 2012
Calculated Member to count fact table
Hi,
I'm having problems creating a calculated member to count specific rows of my fact table.
I need the number of rows matching a filter criteria. I tried it with using the filter expression but without any success.
Lets assume the following:
ID ColumnX ColumnY
1 A ABC1
2 B ABC2
3 A DEF1
DimensionX is based on ColumnX
DimensionY is based on ColumnY
Totals is a measure with a row binding lets say count(ID)
TotalsNoBinding is a measure with row binding and NO aggregation (None)
I would assume that a Calculated measure based on
Count(Filter([Measures].[TotalsNoBinding], [DimensionX].[A ]))
would result the count of "rows" affected by filtering the DimensionX by just allowing the Value A.
I guess I have a understanding problem somewhere. I hope someone can give the right hint to fix the problem. What would be the right way to implement this?
Thanks.
ErtanO
Try to use named calculation in datasource view in spite of create calculated member...
regards!
|||PedroCGD
Thank you...that was the right hint!