Showing posts with label range. Show all posts
Showing posts with label range. Show all posts

Sunday, March 25, 2012

Cursor Help Please

I have a requirement for a user to access time sheet information by accessing a SharePoint portal listing. They will be required enter a date range. The login will be based on their domain access.

Based on the query below, I can return a result set which gives the user all rows they'll need, grouped accordingly and based on a date range. Except for a required billable percentage figure. A billable percentage is defined as billable hours / total hours * 100 or based on the query below;

day1 through 7_hr1 [Worked_hrs] where the project <> admin (@.Worked_hrs_B), divided by the total [Worked_hrs](@.Total_Worked_hrs).

I'm pretty sure I need to use a cursor which will tally all the @.Worked_hrs_NB rows, and another cursor which will tally @.Total_Worked_hrs rows and then divide the two variables * 100, to return it in the @.Billable variable.

This is where I get lost. I'm ashamed to say that my TSQL is rusty & weak at best. Rather than confuse anyone with my idea of cursor syntax, I left it out of this query, & just included the variables I assumed would fit.

A down'n'dirty cursor lesson would be most appreciated (If that's what this needs). Thanks in advance for your help.

DECLARE
@.pe_date1 AS SMALLDATETIME, --Prompt
@.pe_date2 AS SMALLDATETIME, --Prompt
@.emp_id AS CHAR (30), --Login
@.Worked_hrs_B AS INT,
@.Total_Worked_hrs AS INT,
@.Precent AS INT
SET @.pe_date1 = '6/01/2004'
SET @.pe_date2 = '7/01/2005'
SET @.emp_id = 'degajx'
************************************************************************
SET @.Worked_hrs_B = '' Here's where I get lost
SET @.Total_Worked_hrs = '' with the variables & the
SET @.Precent = '' --Make Header Info cursor to populate them.
************************************************************************
SELECT
pjlabhdr.docnbr
, pjlabhdr.pe_date
, pjlabdet.project
, pjlabdet.pjt_entity
, pjlabdet.ld_desc
, (
pjlabdet.day1_hr1 +
pjlabdet.day2_hr1 +
pjlabdet.day3_hr1 +
pjlabdet.day4_hr1 +
pjlabdet.day5_hr1 +
pjlabdet.day6_hr1 +
pjlabdet.day7_hr1
) AS [Worked_hrs]
, pjemploy.manager1
, ltle.employeename AS [Manager] --Make Header Info
, SubAcct.Descr --Make Header Info ************************************************************************
, @.Percent AS [Billable %] --An accurate return, though repeating would be fine.
************************************************************************
FROM IEM_Cut.dbo.PJLABHDR pjlabhdr
INNER JOIN
IEM_Cut.dbo.PJEMPLOY
ON pjlabhdr.employee = pjemploy.employee
Inner JOIN
labortool..laboremployee ltle (NOLOCK)
ON ltle.empid = pjemploy.manager1
LEFT OUTER JOIN
IEM_Cut.dbo.PJLABDET pjlabdet
ON pjlabhdr.docnbr = pjlabdet.docnbr
LEFT OUTER JOIN
IEM_Cut.dbo.SubAcct SubAcct
ON pjemploy.gl_subacct = SubAcct.Sub
WHERE
( pjlabdet.day1_hr1 <> 0
OR pjlabdet.day2_hr1 <> 0
OR pjlabdet.day3_hr1 <> 0
OR pjlabdet.day4_hr1 <> 0
OR pjlabdet.day5_hr1 <> 0
OR pjlabdet.day6_hr1 <> 0
OR pjlabdet.day7_hr1 <> 0
)
AND pjlabhdr.CpnyID_home = 'IEM'
AND pjlabhdr.pe_date BETWEEN CONVERT (varchar, @.pe_date1 , 107) AND CONVERT (varchar, @.pe_date2 , 107)
AND pjlabhdr.employee = @.emp_id
ORDER BY
pjlabhdr.pe_date ASC --Group
, pjlabhdr.docnbr ASC --Group
, pjlabdet.project ASC --Group
, pjlabdet.pjt_entity ASC --Group

You don't really need a cursor. You can write two queries that performs the required SUM operations and divide the results. For example:

select (select sum(...) from ....)/((select sum(...) from ...)*100.0) as billable_per

See Books Online for more details on how to write scalar queries, group by, expressions etc.

sql

Thursday, March 22, 2012

Cursor and cursorless performance

Hi

I am doing the Serial Balance Report

The data is given in a range format i need to culculate the balance,for your information below is an example

Given Stock In Serial Range

10000 - 19999

Stock Out

15000 - 15999

Balance (this is what i calculate out)

10000-14999

16000 -19999

First Loop

BEGIN

--Given the Stock Out Get the Source Stock In and put it into another cursor(Normarlly just 1 record will found)

SECOND LOOP

BEGIN

--calculation

END

END

Previously Im using 2 cursor to loop and perform the calculation, due to the slow performance i change it to cursorless.

I have found that the first 1000 of 55492(2 Month) data its use almost 10 min to finish up the loop, 2000 used 30 min. The performance is decreasing, I have use up to 17 hour but still havent finish 55492 records.

Please Advice.

You are going to have to be more specific, I think, unless this exact problem reminds them of a problem they have. Can you build a small example and show how you have done it?|||


IF OBJECT_ID('tempdb..#tblBalance') IS NOT NULL
DROP Table #tblBalance

Create Table #tblBalance
(
RowID numeric(18,0) IDENTITY(1, 1) not null,
SerialNoFrom nvarchar(50),
SerialNoTo nvarchar(50))

Declare @.SerialNoFrom varchar(50)
Declare @.SerialNoTo varchar(50)
Declare @.FrontSerialNoFrom nvarchar(50)
Declare @.EndSerialNoTo nvarchar(50)
Declare @.FrontSerialNoFromNext nvarchar(50)
Declare @.EndSerialNoToNext nvarchar(50)
Declare @.SKUCode nvarchar(50)
Declare @.SLoc nvarchar(10)
Declare @.Tmp nvarchar(12)
Declare @.tmpCount integer
Declare @.sql varchar(100)

Declare @.count int
Declare @.iRow int
Declare @.countNext int
Declare @.iRowNext int

SET @.count = (SELECT MAX(RowID) FROM multicom_Qty_Minus)

SET @.iRow = 1

Print 'Total Count' + convert(varchar,@.count)
WHILE @.iRow <= @.count
BEGIN
PRINT 'Current Count ' + Convert(varchar,@.iRow)
PRINT 'GET SERIAL NO FROM'
SET @.SerialNoFrom = (SELECT SerialNoFrom FROM multicom_Qty_Minus WHERE isnumeric(SerialNoTo) = 1 and isnumeric(SerialNoFrom) = 1 AND SerialNoFrom <> '' AND SerialNoTo <> '' AND RowID = @.iRow AND SKUCode <> '100000017' AND
Case when SerialNoFrom <> '' AND SerialNoFrom <> '' AND isnumeric(SerialNoTo) = 1 AND isnumeric(SerialNoFrom) = 1 then
((Convert(numeric,SerialNoTo)-Convert(numeric,SerialNoFrom))+1) END = Quantity)
PRINT 'GET SERIAL NO TO'
SET @.SerialNoTo = (SELECT SerialNoTo FROM multicom_Qty_Minus WHERE isnumeric(SerialNoTo) = 1 and isnumeric(SerialNoFrom) = 1 AND SerialNoFrom <> '' AND SerialNoTo <> '' AND RowID = @.iRow AND SKUCode <> '100000017' AND
Case when SerialNoFrom <> '' AND SerialNoFrom <> '' AND isnumeric(SerialNoTo) = 1 AND isnumeric(SerialNoFrom) = 1 then
((Convert(numeric,SerialNoTo)-Convert(numeric,SerialNoFrom))+1) END = Quantity)
PRINT 'GET SLOC'
SET @.SLoc = (SELECT SLoc FROM multicom_Qty_Minus WHERE isnumeric(SerialNoTo) = 1 and isnumeric(SerialNoFrom) = 1 AND SerialNoFrom <> '' AND SerialNoTo <> '' AND RowID = @.iRow AND SKUCode <> '100000017' AND
Case when SerialNoFrom <> '' AND SerialNoFrom <> '' AND isnumeric(SerialNoTo) = 1 AND isnumeric(SerialNoFrom) = 1 then
((Convert(numeric,SerialNoTo)-Convert(numeric,SerialNoFrom))+1) END = Quantity)
PRINT 'GET SKUCode'
SET @.SKUCode = (SELECT SKUCode FROM multicom_Qty_Minus WHERE isnumeric(SerialNoTo) = 1 and isnumeric(SerialNoFrom) = 1 AND SerialNoFrom <> '' AND SerialNoTo <> '' AND RowID = @.iRow AND SKUCode <> '100000017' AND
Case when SerialNoFrom <> '' AND SerialNoFrom <> '' AND isnumeric(SerialNoTo) = 1 AND isnumeric(SerialNoFrom) = 1 then
((Convert(numeric,SerialNoTo)-Convert(numeric,SerialNoFrom))+1) END = Quantity)

PRINT @.SerialNoFrom + '-' + @.SerialNoTo
PRINT 'SKUCode ' + @.SKUCode
PRINT 'SLoc ' + @.SLoc

INSERT INTO #tblBalance
SELECT SerialNoFrom,SerialNoTo FROM multicom WHERE isnumeric(SerialNoTo) = 1 and isnumeric(SerialNoFrom) = 1 AND
QuantityPlus > 0 AND
((Convert(numeric,SerialNoTo)-Convert(numeric,SerialNoFrom))+1) = Quantity AND
LEN(SerialNoTo) = LEN(@.SerialNoTo) AND LEN(SerialNoFrom) = LEN(@.SerialNoFrom) AND
SKUCode = @.SKUCode AND SLoc = @.SLoc AND
convert(numeric,SerialNoFrom) <> convert(numeric,@.SerialNoFrom) AND
convert(numeric,SerialNoTo)<>convert(numeric,@.SerialNoTo)AND
((CONVERT(numeric,SerialNoFrom) <= CONVERT(numeric,@.SerialNoFrom) AND
CONVERT(numeric,SerialNoTo) >= CONVERT(numeric,@.SerialNoTo)) OR
(CONVERT(numeric,SerialNoTo) >= CONVERT(numeric,@.SerialNoTo) AND
CONVERT(numeric,SerialNoFrom)<= CONVERT(numeric,@.SerialNoFrom)))

SET @.countNext = @.@.ROWCOUNT
SET @.iRowNext = 1

-IF @.countNext == 0 then put the Searil into the ErrorQtyMinus
/*
--
--
*/
IF @.CountNext = 0
BEGIN
INSERT INTO multicom_Error_Qty_Minus
SELECT Plnt,SLoc,
SLocDescription,SKUCode,MvT,PostDate,DocDate,[Serial No (from Material Doc.)],[Serial No (from Delivery Item)],
MatDoc,Item,InvNo,Quantity,Sign,Payer,UserID,PONo,SOff,DeliveryNo,PODate,SOrg,Salesman,MatGroup,DC,SoldTo,CoCd,InvoiceDt,
SerialNoTo,SerialNoFrom,SLocFrom,SLocTo,SalesOffDesc,PayerName1,PrdName,MvTDesc,StdCost,PrdGrp4,QuantityPlus,QuantityMinus
FROM multicom_Qty_Minus WHERE RowID = @.iRow
END
PRINT 'Total 2nd loop COUNT'
PRINT @.countNext
WHILE @.iRowNext <= @.countNext
BEGIN
Print 'Current 2nd loop Count ' + convert(varchar,@.iRowNext)
SET @.FrontSerialNoFrom = (SELECT SerialNoFrom From #tblBalance WHERE RowID = @.iRowNext)
SET @.EndSerialNoTo = (SELECT SerialNoTo From #tblBalance WHERE RowID = @.iRowNext)
Print @.FrontSerialNoFrom + '-' + @.EndSerialNoTo

IF ISNUMERIC(@.FrontSerialNoFrom) = 1 AND ISNUMERIC(@.EndSerialNoTo) = 1 AND ISNUMERIC(@.SerialNoFrom)=1 AND ISNUMERIC(@.SerialNoTo)= 1
BEGIN
IF CONVERT(numeric,@.SerialNoFrom) > CONVERT(numeric,@.FrontSerialNoFrom)
BEGIN
SET @.Tmp = (CONVERT(numeric,@.SerialNoFrom) -1)
SET @.Tmp = REPLICATE('0',(12 - (len(@.Tmp)))) + @.Tmp
PRINT 'BALANCE'
PRINT @.FrontSerialNoFrom + '-' + CONVERT(nvarchar(12),@.Tmp)

PRINT 'QUANTITY'
PRINT (Convert(numeric,@.Tmp) - (Convert(numeric,@.FrontSerialNoFrom)) + 1)

Insert INTO multicom_Balance
Select Plnt,SLoc,SLocDescription,SKUCode,MvT,PostDate,DocDate,MatDoc,Item,
(Convert(numeric,@.Tmp) - (Convert(numeric,@.FrontSerialNoFrom)) + 1),
Convert(nvarchar(12),@.Tmp),@.FrontSerialNoFrom,SalesOffDesc,PayerName1,PrdName,MvTDesc,StdCost,QuantityPlus,
QuantityMinus From multicom_Qty_Minus WHERE RowID = @.iRow
END

IF CONVERT(numeric,@.EndSerialNoTo) > CONVERT(numeric,@.SerialNoTo)
BEGIN
SET @.Tmp = (CONVERT(numeric,@.SerialNoTo) + 1)
SET @.Tmp = REPLICATE('0',(12 - (len(@.Tmp)))) + @.Tmp
PRINT 'Last Balance'
PRINT CONVERT(nvarchar(12),@.Tmp) + '-' + @.EndSerialNoTo

PRINT 'QUANTITY'
PRINT (Convert(numeric,@.EndSerialNoTo) - (Convert(numeric,@.Tmp)) + 1)
Insert INTO multicom_Balance
Select Plnt,SLoc,SLocDescription,SKUCode,MvT,PostDate,DocDate,MatDoc,Item,
(Convert(numeric,@.EndSerialNoTo) - (Convert(numeric,@.Tmp)) + 1),
@.EndSerialNoTo,CONVERT(nvarchar(12),@.Tmp),SalesOffDesc,PayerName1,PrdName,MvTDesc,StdCost,QuantityPlus,
QuantityMinus From multicom_Qty_Minus WHERE RowID = @.iRow
END
SET @.FrontSerialNoFrom = ''
SET @.EndSerialNoTo = ''
END
SET @.iRowNext = @.iRowNext + 1
END
Truncate Table #tblBalance
SET @.iRow = @.iRow + 1
END

I think It is my problem not SQL SERVER problem, Is there any way i can speed up the query?

|||

I don;t know what kind of logic you are using behind this query... But I am willing to say few generic comments..

Replace the following statements

SET @.SerialNoFrom = (SELECT SerialNoFrom FROM multicom_Qty_Minus WHERE isnumeric(SerialNoTo) = 1 and isnumeric(SerialNoFrom) = 1 AND SerialNoFrom <> '' AND SerialNoTo <> '' AND RowID = @.iRow AND SKUCode <> '100000017' AND
Case when SerialNoFrom <> '' AND SerialNoFrom <> '' AND isnumeric(SerialNoTo) = 1 AND isnumeric(SerialNoFrom) = 1 then
((Convert(numeric,SerialNoTo)-Convert(numeric,SerialNoFrom))+1) END = Quantity)
PRINT 'GET SERIAL NO TO'
SET @.SerialNoTo = (SELECT SerialNoTo FROM multicom_Qty_Minus WHERE isnumeric(SerialNoTo) = 1 and isnumeric(SerialNoFrom) = 1 AND SerialNoFrom <> '' AND SerialNoTo <> '' AND RowID = @.iRow AND SKUCode <> '100000017' AND
Case when SerialNoFrom <> '' AND SerialNoFrom <> '' AND isnumeric(SerialNoTo) = 1 AND isnumeric(SerialNoFrom) = 1 then
((Convert(numeric,SerialNoTo)-Convert(numeric,SerialNoFrom))+1) END = Quantity)
PRINT 'GET SLOC'
SET @.SLoc = (SELECT SLoc FROM multicom_Qty_Minus WHERE isnumeric(SerialNoTo) = 1 and isnumeric(SerialNoFrom) = 1 AND SerialNoFrom <> '' AND SerialNoTo <> '' AND RowID = @.iRow AND SKUCode <> '100000017' AND
Case when SerialNoFrom <> '' AND SerialNoFrom <> '' AND isnumeric(SerialNoTo) = 1 AND isnumeric(SerialNoFrom) = 1 then
((Convert(numeric,SerialNoTo)-Convert(numeric,SerialNoFrom))+1) END = Quantity)
PRINT 'GET SKUCode'
SET @.SKUCode = (SELECT SKUCode FROM multicom_Qty_Minus WHERE isnumeric(SerialNoTo) = 1 and isnumeric(SerialNoFrom) = 1 AND SerialNoFrom <> '' AND SerialNoTo <> '' AND RowID = @.iRow AND SKUCode <> '100000017' AND
Case when SerialNoFrom <> '' AND SerialNoFrom <> '' AND isnumeric(SerialNoTo) = 1 AND isnumeric(SerialNoFrom) = 1 then
((Convert(numeric,SerialNoTo)-Convert(numeric,SerialNoFrom))+1) END = Quantity)

with

SELECT
@.SerialNoFrom=SerialNoFrom,
@.SerialNoTo =SerialNoTo,
@.SLoc=SLoc,
@.SKUCode=SKUCode
FROM
multicom_Qty_Minus WHERE isnumeric(SerialNoTo) = 1 and isnumeric(SerialNoFrom) = 1 AND SerialNoFrom <> '' AND SerialNoTo <> '' AND RowID = @.iRow AND SKUCode <> '100000017' AND
Case when SerialNoFrom <> '' AND SerialNoFrom <> '' AND isnumeric(SerialNoTo) = 1 AND isnumeric(SerialNoFrom) = 1 then
((Convert(numeric,SerialNoTo)-Convert(numeric,SerialNoFrom))+1) END = Quantity


Replace the following statements

SET @.FrontSerialNoFrom = (SELECT SerialNoFrom From #tblBalance WHERE RowID = @.iRowNext)
SET @.EndSerialNoTo = (SELECT SerialNoTo From #tblBalance WHERE RowID = @.iRowNext)

with

SELECT @.FrontSerialNoFrom=SerialNoFrom, @.EndSerialNoTo=SerialNoTo From #tblBalance WHERE RowID = @.iRowNext

When you assing the values from the Select statement you need not to use SET statement; Advantage the same query executed more than once to fetch the value when you use SET, but the suggested query will be executed once and fetch all the required data....

|||

WOW,Thanks a lot.

Tuesday, March 20, 2012

Current month syntax

A little help please...
I need to extract records in which the FileRecDate falls within the current
month/current year range. Also may need to filter by previous month/current
year; current year and prior year.
Any ideas?
Thanks,
Kenselect getdate()
Also:
select datepart(mm,getdate())
select datepart(dd,getdate())
select datepart(yy,getdate())
It is possible to get more fancy. You could declare a "start" and an "end"
variable and set the values according to your business logic. The variables
would then be used to filter your data within your query/stored procedure.
Keith
"Ken D." <KenD@.discussions.microsoft.com> wrote in message
news:49A7FD76-49BF-41D8-8437-9BD015FEF288@.microsoft.com...
>A little help please...
> I need to extract records in which the FileRecDate falls within the
> current
> month/current year range. Also may need to filter by previous
> month/current
> year; current year and prior year.
> Any ideas?
> Thanks,
> Ken|||Keith,
Actually, I tried this logic and it worked.
WHERE Month(FileRecDate) = Month(GetDate())AND
Year(FileRecDate)=Year(GetDate())
Thank you so much for your input...
Ken
"Keith Kratochvil" wrote:

> select getdate()
> Also:
> select datepart(mm,getdate())
> select datepart(dd,getdate())
> select datepart(yy,getdate())
> It is possible to get more fancy. You could declare a "start" and an "end
"
> variable and set the values according to your business logic. The variabl
es
> would then be used to filter your data within your query/stored procedure.
> --
> Keith
>
> "Ken D." <KenD@.discussions.microsoft.com> wrote in message
> news:49A7FD76-49BF-41D8-8437-9BD015FEF288@.microsoft.com...
>
>|||> WHERE Month(FileRecDate) = Month(GetDate())AND
> Year(FileRecDate)=Year(GetDate())
Ugh, how was performance? You might not notice while the table is small,
but wait until you have a reasnable amount of data. If you have an index on
FileRecDate (which you should), you might try something along these lines:
DECLARE @.sd SMALLDATETIME
SET @.sd = DATEDIFF(DAY,DAY(GETDATE())-1,GETDATE())
SELECT ...
WHERE FileRecDate >= @.sd
AND FileRecDate < DATEADD(MONTH, 1, @.sd)
A|||Ken D. wrote:
> Keith,
> Actually, I tried this logic and it worked.
>
> WHERE Month(FileRecDate) = Month(GetDate())AND
> Year(FileRecDate)=Year(GetDate())
VERY BAD and here is why:
You force SQL server to calculate Month(FileRecDate) and
Year(FileRecDate) for each row in the table and prevent
it from using an index that you may have on FileRecDate.
It is much better to write something like this:
WHERE FileRecDate BETWEEN @.MonthStartDateTime and @.MonthEndDateTime
Both @.MonthStartDateTime and @.MonthEndDateTime can be either
calculated by the SQL server (you can use CONVERT function)
or passed as parameters.
NEVER, NEVER force the calculation on a field in the WHERE
clause unless it is absolutely necessary.
Yura
> Thank you so much for your input...
> Ken
> "Keith Kratochvil" wrote:
>|||Ken,
Do not manipulate the column and try to use the pattern:
column <operator> constant
so sql server can considers the expression as a search argument.
Transact-SQL Query
SQL Server Performance Tuning Tips
http://www.sql-server-performance.com/transact_sql.asp
...
where
FileRecDate >= convert(varchar(6), getdate(), 112) + '01'
and FileRecDate < dateadd(month, 1, convert(varchar(6), getdate(), 112) +
'01')
Example:
set showplan_text on
go
select
*
from
northwind.dbo.orders
where
orderdate >= convert(varchar(6), getdate(), 112) + '01'
and orderdate < dateadd(month, 1, convert(varchar(6), getdate(), 112) + '01'
)
go
select
*
from
northwind.dbo.orders
where
year(orderdate) = year(getdate())
and month(orderdate) = month(getdate())
go
set showplan_text off
go
See that in the first execution plan, sql server will performs an index s
in index [OrderDate], but in the second, it will scan index [pk_Orders].
AMB
"Ken D." wrote:
> Keith,
> Actually, I tried this logic and it worked.
>
> WHERE Month(FileRecDate) = Month(GetDate())AND
> Year(FileRecDate)=Year(GetDate())
> Thank you so much for your input...
> Ken
> "Keith Kratochvil" wrote:
>|||> WHERE FileRecDate BETWEEN @.MonthStartDateTime and @.MonthEndDateTime
BETWEEN can be bad too; not necessarily for performance, but certainly when
constructing the end of the range, particularly if the datatype is datetime,
and/or is converted between datetime and smalldatetime, and/or the values in
the table can fall on midnight of the end of the range OR only contain
dates.
http://www.aspfaq.com/2280
A|||Aaron,
I dropped the code in and it works great. Could you explain the syntax for
previous month or current year.
Ken
"Aaron Bertrand [SQL Server MVP]" wrote:

> Ugh, how was performance? You might not notice while the table is small,
> but wait until you have a reasnable amount of data. If you have an index
on
> FileRecDate (which you should), you might try something along these lines:
> DECLARE @.sd SMALLDATETIME
> SET @.sd = DATEDIFF(DAY,DAY(GETDATE())-1,GETDATE())
> SELECT ...
> WHERE FileRecDate >= @.sd
> AND FileRecDate < DATEADD(MONTH, 1, @.sd)
> A
>
>|||Aaron Bertrand [SQL Server MVP] wrote:
>
> BETWEEN can be bad too; not necessarily for performance, but certainly whe
n
> constructing the end of the range, particularly if the datatype is datetim
e,
> and/or is converted between datetime and smalldatetime, and/or the values
in
> the table can fall on midnight of the end of the range OR only contain
> dates.
I simply assumed that Ken knows these caveats.
I usually define
@.StartDateTime and @.EndDateTime
as
'<month>/01/<year>' (i.e. 12 am) and '<month>/<end day>/<year>
11:59:59.9999 pm'
Or it can be as simple as
@.EndDateTime = DATEADD(mm, 1, @.StartDateTime )
and
WHERE (FileRecDate >= @.StartDateTime AND FileRecDate < @.EndDateTime)|||> I simply assumed that Ken knows these caveats.
I try not to make assumptions here. I would rather overload with
information than miss something and his app breaks.

> '<month>/01/<year>' (i.e. 12 am) and '<month>/<end day>/<year>
> 11:59:59.9999 pm'
I see two problems here.
(1) If you have dateformat d/m/y or English regional settings or French
language, some of these might break (depending on the month). If you're
going to use strings (which you don't have to do), you should at least
strive for ISO standard dates that are unambiguous and cannot be by
people or software (e.g. YYYYMMDD or YYYY-MM-DDTHH:MM:SS[.ms]).
(2) If you have smalldatetime, guess what happens? Your 23:59.9999 gets
rounded up to the next day. That might be bad, depending on the nature of
the data (e.g. you might erroneously include data from the next day, but
timestamped at midnight). In many systems, time is irrelevant (and often
stripped), so this is a common pitfall to watch our for.
I strongly recommend the following topics:
http://www.aspfaq.com/2023
http://www.karaszi.com/SQLServer/info_datetime.asp

Current date Prior year date

In details two seperate formulas for date (current range ie: 4/1/06 to 4/30/06), second formula for prior year same month and day range. Grouping is daily.
The formulas work but are seperated by range not picked. How do I get the date ranges side by side for comparison. I am not using cross-tab.
Any help always appreciated.

ok, after starting from square one I finally have the data I was looking for but....
formatting and suppression not doing as I had hoped.
The report looks like this:

Column1 Column2 Column3 Column4 Column5
Current date data data Prior Year data
4/1/05: Fri 200
4/2/05: Sat 47
4/1/06: Sat 247
4/3/06: Mon 30

How do I get these to line up in the same row without subreports?
I have suppressed everything I can think of...

HelpCan you post some sample data and the result you want?

Wednesday, March 7, 2012

Cube Size Estimation formula....

We need to estimate the size of a cube that will eventually have.... which
will get to the multi-terabyte range when mature....

I have a formula I picked up on the web below, but the sizes projected seem enormous... based on the data going in...

STORAGE FORMULA ESTIMATE - measure group storage (bytes) = (((2 * total # of attributes) + (4 * # of measures)) * # of fact records) / 3
Use the formula for each measure group in UDM model and sum the results. The total # of attributes argument reflects the # of attributes in dimensions that intersect the measure group.

Does anyone have another way of estimating cube size to validate this formula?

Regards,

Ray Cochrane, CPA
BI Consultant

Well. You can use a general rule of Analysis Services data being about 1/4 - 1/3 size of the same data stored in relational database.

Edward.
--
This posting is provided "AS IS" with no warranties, and confers no rights.

|||

Hi Edward,

I assume you would apply this rule of thumb to the size of just the data, i.e. excluding indexes etc. Is that correct?

Also, do you know of any links referencing this rule?

Cheers, Rob.

|||

Hmm :)

You call me to find you some references to this rule.

Here is some data for Analysis Services 2000. http://www.sqlmag.com/Article/ArticleID/19999/sql_server_19999.html
The data for T3 relational database was about 1.2 TB and data in AS was compressed down to 471GB

AS 2005 is behaving similarly.

Hope that helps;

Edward.
--
This posting is provided "AS IS" with no warranties, and confers no rights.