Showing posts with label wrong. Show all posts
Showing posts with label wrong. Show all posts

Sunday, March 11, 2012

AS2005. Aggregate - Last Argument = Bug?

Hi,

some people say that the function aggregate() perfoms quicker without last argument. It's right.
But witout last argument it can returns wrong result. It is nasty :-(

For example

WITH
member [Date].[Calendar].[Column 0] as AGGREGATE({
[Date].[Calendar].[Month].&[2004]&[1],
[Date].[Calendar].[Month].&[2004]&[2],
[Date].[Calendar].[Month].&[2004]&[3],
[Date].[Calendar].[Month].&[2004]&[4],
[Date].[Calendar].[Month].&[2004]&[5],
[Date].[Calendar].[Month].&[2004]&Devil,
[Date].[Calendar].[Month].&[2004]&[7],
[Date].[Calendar].[Month].&[2004]&Music}
)
--, Measures.CurrentMember)

SET [RowSet0] AS {[Customer].[Customer].[All Customers].children}
SET [RowSet1] AS topcount([RowSet0],100,([Date].[Calendar].[Column 0],[Measures].[Internet Sales Amount]))
SET [TotalSet] AS [RowSet1]

SELECT {[Date].[Calendar].[Column 0]} ON COLUMNS,
CROSSJOIN({[Customer].[Customer].[All Customers],[RowSet1]},{[Measures].[Internet Sales Amount], [Measures].[Internet Order Count]})
ON ROWS
FROM [Adventure Works]

I wonder... is this the same problem as I describe here:
http://cwebbbi.spaces.live.com/blog/cns!7B84B0F2C239489A!889.entry
? Looks very much like it. In which case it's a feature and not a bug, but I agree, it's a pretty confusing one and something that does need to be changed.

Chris

Friday, February 24, 2012

array?

Hello,
I was wondering if there is an alternative for an array in sql server.
What i would like (correct me if i approach this the wrong way) is an array
which i can use in a where clause based on a variable/parameter.
for example:
using a select statement to retrieve a list of titles or id's as integers.
titles:
book1
book2
book3
id's:
1
2
3
Pass that list into a variable/paramater of a second select statement like
select * from mytable where titles in @.variable/parameter. In this case the
values should be concated with quotes and commas like 'book1', 'book2'. If
the values are integer then 1, 2, 3.
Is this possible?
----
This mailbox protected from junk email by MailFrontier Desktop
from MailFrontier, Inc. http://info.mailfrontier.comhttp://www.sommarskog.se/arrays-in-sql.html
Roji. P. Thomas
Net Asset Management
https://www.netassetmanagement.com
"Jason" <jlewis@.homail.com> wrote in message
news:ebwwjblHFHA.1476@.TK2MSFTNGP09.phx.gbl...
> Hello,
> I was wondering if there is an alternative for an array in sql server.
> What i would like (correct me if i approach this the wrong way) is an
> array which i can use in a where clause based on a variable/parameter.
> for example:
> using a select statement to retrieve a list of titles or id's as integers.
> titles:
> book1
> book2
> book3
> id's:
> 1
> 2
> 3
> Pass that list into a variable/paramater of a second select statement like
> select * from mytable where titles in @.variable/parameter. In this case
> the values should be concated with quotes and commas like 'book1',
> 'book2'. If the values are integer then 1, 2, 3.
> Is this possible?
> --
>
> ----
> This mailbox protected from junk email by MailFrontier Desktop
> from MailFrontier, Inc. http://info.mailfrontier.com
>|||Jason
CREATE PROCEDURE array_method_1
@.array nvarchar(4000)
AS
BEGIN
SET NOCOUNT ON
DECLARE @.nsql nvarchar(4000)
SET @.nsql = '
SELECT *
FROM sysobjects
WHERE name IN ( ' + @.array + ')'
PRINT @.nsql
EXEC sp_executesql @.nsql
END
GO
EXEC array_method_1
@.array = '''sysobjects'',''sysindexes'',''syscolu
mns'''
GO
"Jason" <jlewis@.homail.com> wrote in message
news:ebwwjblHFHA.1476@.TK2MSFTNGP09.phx.gbl...
> Hello,
> I was wondering if there is an alternative for an array in sql server.
> What i would like (correct me if i approach this the wrong way) is an
array
> which i can use in a where clause based on a variable/parameter.
> for example:
> using a select statement to retrieve a list of titles or id's as integers.
> titles:
> book1
> book2
> book3
> id's:
> 1
> 2
> 3
> Pass that list into a variable/paramater of a second select statement like
> select * from mytable where titles in @.variable/parameter. In this case
the
> values should be concated with quotes and commas like 'book1', 'book2'. If
> the values are integer then 1, 2, 3.
> Is this possible?
> --
>
> ----
> This mailbox protected from junk email by MailFrontier Desktop
> from MailFrontier, Inc. http://info.mailfrontier.com
>|||I have 6 different ways of doig this, at:
http://vyaskn.tripod.com/passing_ar..._procedures.htm
--
HTH,
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
"Jason" <jlewis@.homail.com> wrote in message
news:ebwwjblHFHA.1476@.TK2MSFTNGP09.phx.gbl...
Hello,
I was wondering if there is an alternative for an array in sql server.
What i would like (correct me if i approach this the wrong way) is an array
which i can use in a where clause based on a variable/parameter.
for example:
using a select statement to retrieve a list of titles or id's as integers.
titles:
book1
book2
book3
id's:
1
2
3
Pass that list into a variable/paramater of a second select statement like
select * from mytable where titles in @.variable/parameter. In this case the
values should be concated with quotes and commas like 'book1', 'book2'. If
the values are integer then 1, 2, 3.
Is this possible?
----
This mailbox protected from junk email by MailFrontier Desktop
from MailFrontier, Inc. http://info.mailfrontier.com

Monday, February 13, 2012

Arithmetic operation failure. Is this a bug, or am I doing something wrong?

I used the following code in a function. The @.infloat is input parameter

For every other number than 16.31, 17.31, 18.31, 19.31 and 20.31 (at least those numbers I checked) the code runs ok. For those numbers the result is wrong.

What I want to do is return a ten digits number left filled with zeros, with the last two digits consitered as decimals.

What I do is multiply the given float with 100.00, and take the resulting integer

But when @.infloat is multiplied with 100.00 and @.infloat in (16.31, 17.31, 18.31, 19.31 and 20.31)

the result is (1630,1730,1830,1930,2030) instead of (1631,1731,1831,1931,2031)..

Can anyone try this ?

declare @.ingood int,

@.stuffme varchar(10),

@.infloat float, @.infl float

set @.infloat=18.31

set @.infloat=isnull(@.infloat,0)

set @.stuffme='0000000000'

set @.infl=@.infloat*(100.00)

select @.infl as infl

set @.ingood=cast(@.infl as int)

select @.ingood as ingood

set @.stuffme=stuff(@.stuffme,11-len(@.ingood),len(@.ingood),@.ingood)

select @.stuffme

Replace

set @.ingood=cast(@.infl as int)

WITH

set @.ingood=cast(@.infl as NUMeERIC (10,2))

|||Do you need high precision ? Floating point data is approximate; not all values in the data type range can be precisely represented.

See here :
select convert(float, 18.31)
Result : 18.309999999999999|||

Hi

I have tried MONEY and NUMERIC datatypes for @.infloat and @.infl from your example. They both work just fine.

Sunday, February 12, 2012

are there anything wrong?

update Countries set CountryName = XMLTable.CountryName,Region = XMLTable.Region, HPEntity = XMLTable.HPEntity, Model = XMLTable.Model, Incoterms = XMLTable.Incoterms, IncotermsDesc = XMLTable.IncotermsDesc, DestCountry = XMLTable.DestCountry
from
(
select CountryCode,
CountryName,
Region,
HPEntity,
Model,
Incoterms,
IncotermsDesc,
DestCountry
from OPENXML(@.xmldoc, N'/Countries/Country')
with ( CountryCode char(2) '@.id',
CountryName varchar(50) 'CountryName',
Region varchar(10) 'Region',
HPEntity varchar(2) 'HPEntity',
Model varchar(50) 'Model',
Incoterms char(3) 'IncotermOffer',
IncotermsDesc varchar(50) 'IncotermDescription',
DestCountry char(2) 'DestinationCountry/@.id')) as XMLTable
where Countries.CountryCode = XMLTable.CountryCode


Are you getting an error when you try to execute this DML? If so, what is the error?

are there anything wrong?

update Countries set CountryName = XMLTable.CountryName,Region = XMLTable.Region, HPEntity = XMLTable.HPEntity, Model = XMLTable.Model, Incoterms = XMLTable.Incoterms, IncotermsDesc = XMLTable.IncotermsDesc, DestCountry = XMLTable.DestCountry
from
(
select CountryCode,
CountryName,
Region,
HPEntity,
Model,
Incoterms,
IncotermsDesc,
DestCountry
from OPENXML(@.xmldoc, N'/Countries/Country')
with ( CountryCode char(2) '@.id',
CountryName varchar(50) 'CountryName',
Region varchar(10) 'Region',
HPEntity varchar(2) 'HPEntity',
Model varchar(50) 'Model',
Incoterms char(3) 'IncotermOffer',
IncotermsDesc varchar(50) 'IncotermDescription',
DestCountry char(2) 'DestinationCountry/@.id')) as XMLTable
where Countries.CountryCode = XMLTable.CountryCode


Are you getting an error when you try to execute this DML? If so, what is the error?

Thursday, February 9, 2012

Are SOX Auditors focused on the wrong things?

The Security Catalyst had an interesting post last week, The
Psychology of Fraud -Revisited.
In the post, Sarbanes-Oxley auditors are criticized for focusing on
minutia that is costing corporations millions, while the real cause of
fraud is corrupted humans.
In developing this argument, the author draws upon a model developed
in the early 1950's by Dr. Donald Cressey, a criminologist whose
research focused on embezzlers, called the fraud triangle. Where Dr.
Cressey's triangle consisted of pressure, rationalization, and
opportunity, the Security Catalyst altered the points of triangle for
IT fraud to include the following definitions:
- Access. Physical or logical ability to enter, touch, or reach a
resource. In computers, this is often controlled by network rules and
a user id and password.
- Knowledge. To be familiar or have experience with an object or
resource. This means having the concepts and ability on what to do
after you have accessed the resource.
- Intent. The purpose or an anticipated outcome that guides a person's
planned actions. Knowingly causing damage to the resource.
These make a great deal of sense, but the rest of the argument is lost
on me. The author tries to make the case that access rights should not
be scrutinized to the degree they are currently in SOX audits because
it is only a portion of the fraud triangle. Improper access doesn't
necessarily mean that someone has knowledge or intent.
The post even states "You can't audit against knowledge and intent."
Well, if you can't audit knowledge and intent, don't you have to audit
access? In the absence of a way to detect someone with the knowledge
and intent to perpetrate fraud, don't you have to ensure access is
being provided on an as needed basis?
In my opinion, the author's own statements actually justify why
auditors give access rights the demanding scrutiny they do today. If
access rights are poorly documented and managed, the odds are that
much greater that a person who already has the knowledge and intent
will get the golden key that completes their fraud triangle.
SOX does not prevent or reduce corporate fraud. Its requirements exist so
that a prosecuting attorney can presumptively use a corporation's records as
legal evidence against the corporation's management. Viewed in that light,
the requirements make perfect sense.
Geoff N. Hiten
Senior SQL Infrastructure Consultant
Microsoft SQL Server MVP
<jmichaud@.ecora.com> wrote in message
news:1185212726.689666.6170@.n2g2000hse.googlegroup s.com...
> The Security Catalyst had an interesting post last week, The
> Psychology of Fraud -Revisited.
> In the post, Sarbanes-Oxley auditors are criticized for focusing on
> minutia that is costing corporations millions, while the real cause of
> fraud is corrupted humans.
> In developing this argument, the author draws upon a model developed
> in the early 1950's by Dr. Donald Cressey, a criminologist whose
> research focused on embezzlers, called the fraud triangle. Where Dr.
> Cressey's triangle consisted of pressure, rationalization, and
> opportunity, the Security Catalyst altered the points of triangle for
> IT fraud to include the following definitions:
> - Access. Physical or logical ability to enter, touch, or reach a
> resource. In computers, this is often controlled by network rules and
> a user id and password.
> - Knowledge. To be familiar or have experience with an object or
> resource. This means having the concepts and ability on what to do
> after you have accessed the resource.
> - Intent. The purpose or an anticipated outcome that guides a person's
> planned actions. Knowingly causing damage to the resource.
> These make a great deal of sense, but the rest of the argument is lost
> on me. The author tries to make the case that access rights should not
> be scrutinized to the degree they are currently in SOX audits because
> it is only a portion of the fraud triangle. Improper access doesn't
> necessarily mean that someone has knowledge or intent.
> The post even states "You can't audit against knowledge and intent."
> Well, if you can't audit knowledge and intent, don't you have to audit
> access? In the absence of a way to detect someone with the knowledge
> and intent to perpetrate fraud, don't you have to ensure access is
> being provided on an as needed basis?
> In my opinion, the author's own statements actually justify why
> auditors give access rights the demanding scrutiny they do today. If
> access rights are poorly documented and managed, the odds are that
> much greater that a person who already has the knowledge and intent
> will get the golden key that completes their fraud triangle.
>