Showing posts with label item. Show all posts
Showing posts with label item. Show all posts

Thursday, March 22, 2012

calling javascript on OnSelectedIndexChanged of a drop downlistbox

I have a dropdownlist and a text box.

Once i select the item on a dropdownlist, the control should skip to text box.

Here is the code and i get the error.

'onFocus' is not a member of 'ASP.test_aspx'.

can u plz help me out.

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headrunat="server">

<title>Untitled Page</title>

<scriptlanguage="javascript">

function onFocus()

{

var control = document.getElementById("TextBox1");

if( control != null ) control.focus();

}

</script>

</head>

<body>

<formid="form1"runat="server">

<div>

<asp:DropDownListID="DropDownList1"runat="server"Width="161px"OnSelectedIndexChanged="onFocus()">

<asp:ListItem>Javed</asp:ListItem>

<asp:ListItem>Abid</asp:ListItem>

<asp:ListItem>sajid</asp:ListItem>

<asp:ListItem></asp:ListItem>

</asp:DropDownList>

<asp:TextBoxID="TextBox1"runat="server"></asp:TextBox></div>

</form>

</body>

</html>

The reason you are getting this type of error is because you try to associate (link) JS function with ASP event. when you declare event such as OnSelectedIndexChanged ASP searchs the code behind or C#/VB section for a handler to invoke once this event fires.

A very simple way to diffrentiate between HTML DOM events and ASP events is the case. Note that ASP is always MixCase.

sql

Tuesday, March 20, 2012

calling another stored procedure within a stored procedure?

Hi, I have a while loop stored procedure, I need to send email for each item in the loop using a sendemail stored procedure. I have two question ..

1) I use EXEC PRODUCTION.DBO.SENDMAIL'email@.hotmail.com', 'Start', 'Job Start' in side the while loop stored procedure, but i didn't get any email or error msg. Why?

2) I try to move a file .. how do I find out if the moving is completed successfully?

-- MOVE FILES
SET @.CMD = 'MOVE /Y ' + '"' + @.ORIGINAL_FILE + '"' + ' "' + @.MOVE_FILE + '"'
EXEC master.dbo.xp_cmdshell @.CMD

Thanks for your reply in advance.

1. I have no idea for the stored procedure SENDMAIL. How did you define it?

2. The xp_cmdshell has only 2 return values: 0 or 1. so you can get the returned value as::

declare @.i bit

EXEC @.i=master.dbo.xp_cmdshell @.CMD

select @.i

Seehttp://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_xp_aa-sz_4jxo.asp for more information

|||Firstly try changing the email address to one internal to your domain - i had this problem with a system (although i wasnt sending from SQL i was sending from ASP.NET) but the problem ended up being the exchange server security policy not allowing sending to external addresses programatically. You can register the server with the exchange server to allow this i believe but this is something the server team did not me so i could say how to do it.|||Firstly try changing the email address to one internal to your domain - i had this problem with a system (although i wasnt sending from SQL i was sending from ASP.NET) but the problem ended up being the exchange server security policy not allowing sending to external addresses programatically. You can register the server with the exchange server to allow this i believe but this is something the server team did not me so i could not say how to do it.sql

Sunday, February 19, 2012

Calculation in Matrix

My Matrix has the following structure
Item Jan Feb
--
AAA 200 40
How would I add another column to show the diff. between the two months
Item Jan Feb Diff
--
AAA 200 40 160
Thanks,
JRI don't think you can accomplish this currently with a matrix. As you know,
with a table it is easy but that fixes the number of displayed columns unlike
a matrix. Note that your question is similar to the one posted yesterday
about adding a partial subtotal to a matrix. There were no answers to that
question.
"John" wrote:
> My Matrix has the following structure
> Item Jan Feb
> --
> AAA 200 40
>
> How would I add another column to show the diff. between the two months
> Item Jan Feb Diff
> --
> AAA 200 40 160
>
> Thanks,
> JR|||Substraction is negative addition. Display Feb as 20 but treat it as -20 and
calculate the total.
CD
"B. Mark McKinney" <BMarkMcKinney@.discussions.microsoft.com> wrote in
message news:714B0E8B-B6C4-488B-9DE5-9DA23AD83E39@.microsoft.com...
>I don't think you can accomplish this currently with a matrix. As you know,
> with a table it is easy but that fixes the number of displayed columns
> unlike
> a matrix. Note that your question is similar to the one posted yesterday
> about adding a partial subtotal to a matrix. There were no answers to that
> question.
> "John" wrote:
>> My Matrix has the following structure
>> Item Jan Feb
>> --
>> AAA 200 40
>>
>> How would I add another column to show the diff. between the two months
>> Item Jan Feb Diff
>> --
>> AAA 200 40 160
>>
>> Thanks,
>> JR

Calculation for FIFO

Hi Everybody,
I've provide a sample Purchase Order with some data. I need to maintain a FI
FO (first-in-first-out) for the the sale of item and at the end of the day,
will generate a report which are the Purchase Order with item still unsold.
Example, sold 150 items (80 from id=1, 23 from id=2, 43 from id=3 and 4 from
id=4) , so the query need to display id 4 (still remain with 26) and id 5 (
still remain with 60)
Can someone help me on this query?
Sample Purchase Order table
id date item_code quantity
-- -- -- --
1 2005-01-02 item_A 80
2 2005-01-15 item_A 23
3 2005-02-04 item_A 43
4 2005-02-23 item_A 30
5 2005-03-13 item_A 60
Thanks in advance,
KristeKriste
See, if this helps you
CREATE TABLE #Sales
(
SaleId INT NOT NULL PRIMARY KEY,
SaleDate DATETIME NOT NULL,
ItemCode CHAR(6) NOT NULL,
Quantity INT
)
INSERT INTO #Sales VALUES (1,'2005-01-02', 'item_A',80)
INSERT INTO #Sales VALUES (2,'2005-01-15', 'item_A',23)
INSERT INTO #Sales VALUES (3,'2005-02-04', 'item_A',43)
INSERT INTO #Sales VALUES (4,'2005-02-23', 'item_A',30)
INSERT INTO VALUES (5,'2005-03-13', 'item_A',60)
SELECT * FROM #Sales S
WHERE (
SELECT COUNT(*) FROM #Sales
WHERE ItemCode = S.ItemCode
AND SaleId > S.SaleId
) <= 1
ORDER BY SaleId ASC
"Kriste L" <whiteegg@.hotmail.com> wrote in message news:%23zGe4WGVFHA.3076@.T
K2MSFTNGP12.phx.gbl...
Hi Everybody,
I've provide a sample Purchase Order with some data. I need to maintain a FI
FO (first-in-first-out) for the the sale of item and at the end of the day,
will generate a report which are the Purchase Order with item still unsold.
Example, sold 150 items (80 from id=1, 23 from id=2, 43 from id=3 and 4 from
id=4) , so the query need to display id 4 (still remain with 26) and id 5 (
still remain with 60)
Can someone help me on this query?
Sample Purchase Order table
id date item_code quantity
-- -- -- --
1 2005-01-02 item_A 80
2 2005-01-15 item_A 23
3 2005-02-04 item_A 43
4 2005-02-23 item_A 30
5 2005-03-13 item_A 60
Thanks in advance,
Kriste|||Can u explain how does this query works? I don't quite understand.
If now the sold quantity = 100, how will it return the id=2 to 5?
"Uri Dimant" <urid@.iscar.co.il> wrote in message news:OHfl5gGVFHA.4092@.TK2MS
FTNGP12.phx.gbl...
Kriste
See, if this helps you
CREATE TABLE #Sales
(
SaleId INT NOT NULL PRIMARY KEY,
SaleDate DATETIME NOT NULL,
ItemCode CHAR(6) NOT NULL,
Quantity INT
)
INSERT INTO #Sales VALUES (1,'2005-01-02', 'item_A',80)
INSERT INTO #Sales VALUES (2,'2005-01-15', 'item_A',23)
INSERT INTO #Sales VALUES (3,'2005-02-04', 'item_A',43)
INSERT INTO #Sales VALUES (4,'2005-02-23', 'item_A',30)
INSERT INTO VALUES (5,'2005-03-13', 'item_A',60)
SELECT * FROM #Sales S
WHERE (
SELECT COUNT(*) FROM #Sales
WHERE ItemCode = S.ItemCode
AND SaleId > S.SaleId
) <= 1
ORDER BY SaleId ASC
"Kriste L" <whiteegg@.hotmail.com> wrote in message news:%23zGe4WGVFHA.3076@.T
K2MSFTNGP12.phx.gbl...
Hi Everybody,
I've provide a sample Purchase Order with some data. I need to maintain a FI
FO (first-in-first-out) for the the sale of item and at the end of the day,
will generate a report which are the Purchase Order with item still unsold.
Example, sold 150 items (80 from id=1, 23 from id=2, 43 from id=3 and 4 from
id=4) , so the query need to display id 4 (still remain with 26) and id 5 (
still remain with 60)
Can someone help me on this query?
Sample Purchase Order table
id date item_code quantity
-- -- -- --
1 2005-01-02 item_A 80
2 2005-01-15 item_A 23
3 2005-02-04 item_A 43
4 2005-02-23 item_A 30
5 2005-03-13 item_A 60
Thanks in advance,
Kriste|||Kriste
Can you explain if i add INSERT INTO #Sales VALUES (6,'2005-03-13', 'item_A'
,100) why do I should get back from 2 to 5?
"Kriste L" <whiteegg@.hotmail.com> wrote in message news:eEYiF4HVFHA.1404@.TK2
MSFTNGP09.phx.gbl...
Can u explain how does this query works? I don't quite understand.
If now the sold quantity = 100, how will it return the id=2 to 5?
"Uri Dimant" <urid@.iscar.co.il> wrote in message news:OHfl5gGVFHA.4092@.TK2MS
FTNGP12.phx.gbl...
Kriste
See, if this helps you
CREATE TABLE #Sales
(
SaleId INT NOT NULL PRIMARY KEY,
SaleDate DATETIME NOT NULL,
ItemCode CHAR(6) NOT NULL,
Quantity INT
)
INSERT INTO #Sales VALUES (1,'2005-01-02', 'item_A',80)
INSERT INTO #Sales VALUES (2,'2005-01-15', 'item_A',23)
INSERT INTO #Sales VALUES (3,'2005-02-04', 'item_A',43)
INSERT INTO #Sales VALUES (4,'2005-02-23', 'item_A',30)
INSERT INTO VALUES (5,'2005-03-13', 'item_A',60)
SELECT * FROM #Sales S
WHERE (
SELECT COUNT(*) FROM #Sales
WHERE ItemCode = S.ItemCode
AND SaleId > S.SaleId
) <= 1
ORDER BY SaleId ASC
"Kriste L" <whiteegg@.hotmail.com> wrote in message news:%23zGe4WGVFHA.3076@.T
K2MSFTNGP12.phx.gbl...
Hi Everybody,
I've provide a sample Purchase Order with some data. I need to maintain a FI
FO (first-in-first-out) for the the sale of item and at the end of the day,
will generate a report which are the Purchase Order with item still unsold.
Example, sold 150 items (80 from id=1, 23 from id=2, 43 from id=3 and 4 from
id=4) , so the query need to display id 4 (still remain with 26) and id 5 (
still remain with 60)
Can someone help me on this query?
Sample Purchase Order table
id date item_code quantity
-- -- -- --
1 2005-01-02 item_A 80
2 2005-01-15 item_A 23
3 2005-02-04 item_A 43
4 2005-02-23 item_A 30
5 2005-03-13 item_A 60
Thanks in advance,
Kriste|||Hi Uri,
I think you didn't get my question right. The data here is of Purchase Order
. I have a accumulating sales quantity.
As the sales quantity increase, I need to find out which Purchase Order quan
ity is still unsold.
Eg.
Sold sales quantity = 50, so display Purchase Order 1 to 5
Sold sales quantity = 100, so display Purchase Order 2 to 5
Sold sales quantity = 150, so display Purchase Order 4 to 5
Sample Purchase Order table
id date item_code quantity accumulated inventory
-- -- -- -- --
1 2005-01-02 item_A 80 + 80 = 80
2 2005-01-15 item_A 23 + 23 = 103
3 2005-02-04 item_A 43 + 43 = 146
4 2005-02-23 item_A 30 + 30 = 176
5 2005-03-13 item_A 60 + 60 = 236
"Uri Dimant" <urid@.iscar.co.il> wrote in message news:%23rT3DHIVFHA.3176@.TK2
MSFTNGP12.phx.gbl...
Kriste
Can you explain if i add INSERT INTO #Sales VALUES (6,'2005-03-13', 'item_A'
,100) why do I should get back from 2 to 5?
"Kriste L" <whiteegg@.hotmail.com> wrote in message news:eEYiF4HVFHA.1404@.TK2
MSFTNGP09.phx.gbl...
Can u explain how does this query works? I don't quite understand.
If now the sold quantity = 100, how will it return the id=2 to 5?
"Uri Dimant" <urid@.iscar.co.il> wrote in message news:OHfl5gGVFHA.4092@.TK2MS
FTNGP12.phx.gbl...
Kriste
See, if this helps you
CREATE TABLE #Sales
(
SaleId INT NOT NULL PRIMARY KEY,
SaleDate DATETIME NOT NULL,
ItemCode CHAR(6) NOT NULL,
Quantity INT
)
INSERT INTO #Sales VALUES (1,'2005-01-02', 'item_A',80)
INSERT INTO #Sales VALUES (2,'2005-01-15', 'item_A',23)
INSERT INTO #Sales VALUES (3,'2005-02-04', 'item_A',43)
INSERT INTO #Sales VALUES (4,'2005-02-23', 'item_A',30)
INSERT INTO VALUES (5,'2005-03-13', 'item_A',60)
SELECT * FROM #Sales S
WHERE (
SELECT COUNT(*) FROM #Sales
WHERE ItemCode = S.ItemCode
AND SaleId > S.SaleId
) <= 1
ORDER BY SaleId ASC
"Kriste L" <whiteegg@.hotmail.com> wrote in message news:%23zGe4WGVFHA.3076@.T
K2MSFTNGP12.phx.gbl...
Hi Everybody,
I've provide a sample Purchase Order with some data. I need to maintain a FI
FO (first-in-first-out) for the the sale of item and at the end of the day,
will generate a report which are the Purchase Order with item still unsold.
Example, sold 150 items (80 from id=1, 23 from id=2, 43 from id=3 and 4 from
id=4) , so the query need to display id 4 (still remain with 26) and id 5 (
still remain with 60)
Can someone help me on this query?
Sample Purchase Order table
id date item_code quantity
-- -- -- --
1 2005-01-02 item_A 80
2 2005-01-15 item_A 23
3 2005-02-04 item_A 43
4 2005-02-23 item_A 30
5 2005-03-13 item_A 60
Thanks in advance,
Kriste|||Kriste
Now , you are explained the problem by posting DDL
CREATE TABLE #Sales
(
SaleId INT NOT NULL PRIMARY KEY,
SaleDate DATETIME NOT NULL,
ItemCode CHAR(6) NOT NULL,
Quantity INT
)
INSERT INTO #Sales VALUES (1,'2005-01-02', 'item_A',80)
INSERT INTO #Sales VALUES (2,'2005-01-15', 'item_A',23)
INSERT INTO #Sales VALUES (3,'2005-02-04', 'item_A',43)
INSERT INTO #Sales VALUES (4,'2005-02-23', 'item_A',30)
INSERT INTO #Sales VALUES (5,'2005-03-13', 'item_A',60)
Declare @.Q INT
SET @.Q=100
SELECT * FROM
(
SELECT Saleid,(SELECT SUM(Quantity) FROM #Sales S
WHERE #Sales.Saleid>=S.Saleid )AS Ac
FROM #Sales
) AS DER WHERE Ac>=@.q
"Kriste L" <whiteegg@.hotmail.com> wrote in message news:%23gB%23ePIVFHA.3544
@.TK2MSFTNGP12.phx.gbl...
Hi Uri,
I think you didn't get my question right. The data here is of Purchase Order
. I have a accumulating sales quantity.
As the sales quantity increase, I need to find out which Purchase Order quan
ity is still unsold.
Eg.
Sold sales quantity = 50, so display Purchase Order 1 to 5
Sold sales quantity = 100, so display Purchase Order 2 to 5
Sold sales quantity = 150, so display Purchase Order 4 to 5
Sample Purchase Order table
id date item_code quantity accumulated inventory
-- -- -- -- --
1 2005-01-02 item_A 80 + 80 = 80
2 2005-01-15 item_A 23 + 23 = 103
3 2005-02-04 item_A 43 + 43 = 146
4 2005-02-23 item_A 30 + 30 = 176
5 2005-03-13 item_A 60 + 60 = 236
"Uri Dimant" <urid@.iscar.co.il> wrote in message news:%23rT3DHIVFHA.3176@.TK2
MSFTNGP12.phx.gbl...
Kriste
Can you explain if i add INSERT INTO #Sales VALUES (6,'2005-03-13', 'item_A'
,100) why do I should get back from 2 to 5?
"Kriste L" <whiteegg@.hotmail.com> wrote in message news:eEYiF4HVFHA.1404@.TK2
MSFTNGP09.phx.gbl...
Can u explain how does this query works? I don't quite understand.
If now the sold quantity = 100, how will it return the id=2 to 5?
"Uri Dimant" <urid@.iscar.co.il> wrote in message news:OHfl5gGVFHA.4092@.TK2MS
FTNGP12.phx.gbl...
Kriste
See, if this helps you
CREATE TABLE #Sales
(
SaleId INT NOT NULL PRIMARY KEY,
SaleDate DATETIME NOT NULL,
ItemCode CHAR(6) NOT NULL,
Quantity INT
)
INSERT INTO #Sales VALUES (1,'2005-01-02', 'item_A',80)
INSERT INTO #Sales VALUES (2,'2005-01-15', 'item_A',23)
INSERT INTO #Sales VALUES (3,'2005-02-04', 'item_A',43)
INSERT INTO #Sales VALUES (4,'2005-02-23', 'item_A',30)
INSERT INTO VALUES (5,'2005-03-13', 'item_A',60)
SELECT * FROM #Sales S
WHERE (
SELECT COUNT(*) FROM #Sales
WHERE ItemCode = S.ItemCode
AND SaleId > S.SaleId
) <= 1
ORDER BY SaleId ASC
"Kriste L" <whiteegg@.hotmail.com> wrote in message news:%23zGe4WGVFHA.3076@.T
K2MSFTNGP12.phx.gbl...
Hi Everybody,
I've provide a sample Purchase Order with some data. I need to maintain a FI
FO (first-in-first-out) for the the sale of item and at the end of the day,
will generate a report which are the Purchase Order with item still unsold.
Example, sold 150 items (80 from id=1, 23 from id=2, 43 from id=3 and 4 from
id=4) , so the query need to display id 4 (still remain with 26) and id 5 (
still remain with 60)
Can someone help me on this query?
Sample Purchase Order table
id date item_code quantity
-- -- -- --
1 2005-01-02 item_A 80
2 2005-01-15 item_A 23
3 2005-02-04 item_A 43
4 2005-02-23 item_A 30
5 2005-03-13 item_A 60
Thanks in advance,
Kriste|||Thank Uri, it works.
Btw, the DDL has already been included in my 1st post.
"Uri Dimant" <urid@.iscar.co.il> wrote in message news:OPJNzbIVFHA.1604@.TK2MS
FTNGP10.phx.gbl...
Kriste
Now , you are explained the problem by posting DDL
CREATE TABLE #Sales
(
SaleId INT NOT NULL PRIMARY KEY,
SaleDate DATETIME NOT NULL,
ItemCode CHAR(6) NOT NULL,
Quantity INT
)
INSERT INTO #Sales VALUES (1,'2005-01-02', 'item_A',80)
INSERT INTO #Sales VALUES (2,'2005-01-15', 'item_A',23)
INSERT INTO #Sales VALUES (3,'2005-02-04', 'item_A',43)
INSERT INTO #Sales VALUES (4,'2005-02-23', 'item_A',30)
INSERT INTO #Sales VALUES (5,'2005-03-13', 'item_A',60)
Declare @.Q INT
SET @.Q=100
SELECT * FROM
(
SELECT Saleid,(SELECT SUM(Quantity) FROM #Sales S
WHERE #Sales.Saleid>=S.Saleid )AS Ac
FROM #Sales
) AS DER WHERE Ac>=@.q
"Kriste L" <whiteegg@.hotmail.com> wrote in message news:%23gB%23ePIVFHA.3544
@.TK2MSFTNGP12.phx.gbl...
Hi Uri,
I think you didn't get my question right. The data here is of Purchase Order
. I have a accumulating sales quantity.
As the sales quantity increase, I need to find out which Purchase Order quan
ity is still unsold.
Eg.
Sold sales quantity = 50, so display Purchase Order 1 to 5
Sold sales quantity = 100, so display Purchase Order 2 to 5
Sold sales quantity = 150, so display Purchase Order 4 to 5
Sample Purchase Order table
id date item_code quantity accumulated inventory
-- -- -- -- --
1 2005-01-02 item_A 80 + 80 = 80
2 2005-01-15 item_A 23 + 23 = 103
3 2005-02-04 item_A 43 + 43 = 146
4 2005-02-23 item_A 30 + 30 = 176
5 2005-03-13 item_A 60 + 60 = 236
"Uri Dimant" <urid@.iscar.co.il> wrote in message news:%23rT3DHIVFHA.3176@.TK2
MSFTNGP12.phx.gbl...
Kriste
Can you explain if i add INSERT INTO #Sales VALUES (6,'2005-03-13', 'item_A'
,100) why do I should get back from 2 to 5?
"Kriste L" <whiteegg@.hotmail.com> wrote in message news:eEYiF4HVFHA.1404@.TK2
MSFTNGP09.phx.gbl...
Can u explain how does this query works? I don't quite understand.
If now the sold quantity = 100, how will it return the id=2 to 5?
"Uri Dimant" <urid@.iscar.co.il> wrote in message news:OHfl5gGVFHA.4092@.TK2MS
FTNGP12.phx.gbl...
Kriste
See, if this helps you
CREATE TABLE #Sales
(
SaleId INT NOT NULL PRIMARY KEY,
SaleDate DATETIME NOT NULL,
ItemCode CHAR(6) NOT NULL,
Quantity INT
)
INSERT INTO #Sales VALUES (1,'2005-01-02', 'item_A',80)
INSERT INTO #Sales VALUES (2,'2005-01-15', 'item_A',23)
INSERT INTO #Sales VALUES (3,'2005-02-04', 'item_A',43)
INSERT INTO #Sales VALUES (4,'2005-02-23', 'item_A',30)
INSERT INTO VALUES (5,'2005-03-13', 'item_A',60)
SELECT * FROM #Sales S
WHERE (
SELECT COUNT(*) FROM #Sales
WHERE ItemCode = S.ItemCode
AND SaleId > S.SaleId
) <= 1
ORDER BY SaleId ASC
"Kriste L" <whiteegg@.hotmail.com> wrote in message news:%23zGe4WGVFHA.3076@.T
K2MSFTNGP12.phx.gbl...
Hi Everybody,
I've provide a sample Purchase Order with some data. I need to maintain a FI
FO (first-in-first-out) for the the sale of item and at the end of the day,
will generate a report which are the Purchase Order with item still unsold.
Example, sold 150 items (80 from id=1, 23 from id=2, 43 from id=3 and 4 from
id=4) , so the query need to display id 4 (still remain with 26) and id 5 (
still remain with 60)
Can someone help me on this query?
Sample Purchase Order table
id date item_code quantity
-- -- -- --
1 2005-01-02 item_A 80
2 2005-01-15 item_A 23
3 2005-02-04 item_A 43
4 2005-02-23 item_A 30
5 2005-03-13 item_A 60
Thanks in advance,
Kriste|||Right ,but without accumulated column.
"Kriste L" <whiteegg@.hotmail.com> wrote in message news:%2353RfjIVFHA.3312@.T
K2MSFTNGP09.phx.gbl...
Thank Uri, it works.
Btw, the DDL has already been included in my 1st post.
"Uri Dimant" <urid@.iscar.co.il> wrote in message news:OPJNzbIVFHA.1604@.TK2MS
FTNGP10.phx.gbl...
Kriste
Now , you are explained the problem by posting DDL
CREATE TABLE #Sales
(
SaleId INT NOT NULL PRIMARY KEY,
SaleDate DATETIME NOT NULL,
ItemCode CHAR(6) NOT NULL,
Quantity INT
)
INSERT INTO #Sales VALUES (1,'2005-01-02', 'item_A',80)
INSERT INTO #Sales VALUES (2,'2005-01-15', 'item_A',23)
INSERT INTO #Sales VALUES (3,'2005-02-04', 'item_A',43)
INSERT INTO #Sales VALUES (4,'2005-02-23', 'item_A',30)
INSERT INTO #Sales VALUES (5,'2005-03-13', 'item_A',60)
Declare @.Q INT
SET @.Q=100
SELECT * FROM
(
SELECT Saleid,(SELECT SUM(Quantity) FROM #Sales S
WHERE #Sales.Saleid>=S.Saleid )AS Ac
FROM #Sales
) AS DER WHERE Ac>=@.q
"Kriste L" <whiteegg@.hotmail.com> wrote in message news:%23gB%23ePIVFHA.3544
@.TK2MSFTNGP12.phx.gbl...
Hi Uri,
I think you didn't get my question right. The data here is of Purchase Order
. I have a accumulating sales quantity.
As the sales quantity increase, I need to find out which Purchase Order quan
ity is still unsold.
Eg.
Sold sales quantity = 50, so display Purchase Order 1 to 5
Sold sales quantity = 100, so display Purchase Order 2 to 5
Sold sales quantity = 150, so display Purchase Order 4 to 5
Sample Purchase Order table
id date item_code quantity accumulated inventory
-- -- -- -- --
1 2005-01-02 item_A 80 + 80 = 80
2 2005-01-15 item_A 23 + 23 = 103
3 2005-02-04 item_A 43 + 43 = 146
4 2005-02-23 item_A 30 + 30 = 176
5 2005-03-13 item_A 60 + 60 = 236
"Uri Dimant" <urid@.iscar.co.il> wrote in message news:%23rT3DHIVFHA.3176@.TK2
MSFTNGP12.phx.gbl...
Kriste
Can you explain if i add INSERT INTO #Sales VALUES (6,'2005-03-13', 'item_A'
,100) why do I should get back from 2 to 5?
"Kriste L" <whiteegg@.hotmail.com> wrote in message news:eEYiF4HVFHA.1404@.TK2
MSFTNGP09.phx.gbl...
Can u explain how does this query works? I don't quite understand.
If now the sold quantity = 100, how will it return the id=2 to 5?
"Uri Dimant" <urid@.iscar.co.il> wrote in message news:OHfl5gGVFHA.4092@.TK2MS
FTNGP12.phx.gbl...
Kriste
See, if this helps you
CREATE TABLE #Sales
(
SaleId INT NOT NULL PRIMARY KEY,
SaleDate DATETIME NOT NULL,
ItemCode CHAR(6) NOT NULL,
Quantity INT
)
INSERT INTO #Sales VALUES (1,'2005-01-02', 'item_A',80)
INSERT INTO #Sales VALUES (2,'2005-01-15', 'item_A',23)
INSERT INTO #Sales VALUES (3,'2005-02-04', 'item_A',43)
INSERT INTO #Sales VALUES (4,'2005-02-23', 'item_A',30)
INSERT INTO VALUES (5,'2005-03-13', 'item_A',60)
SELECT * FROM #Sales S
WHERE (
SELECT COUNT(*) FROM #Sales
WHERE ItemCode = S.ItemCode
AND SaleId > S.SaleId
) <= 1
ORDER BY SaleId ASC
"Kriste L" <whiteegg@.hotmail.com> wrote in message news:%23zGe4WGVFHA.3076@.T
K2MSFTNGP12.phx.gbl...
Hi Everybody,
I've provide a sample Purchase Order with some data. I need to maintain a FI
FO (first-in-first-out) for the the sale of item and at the end of the day,
will generate a report which are the Purchase Order with item still unsold.
Example, sold 150 items (80 from id=1, 23 from id=2, 43 from id=3 and 4 from
id=4) , so the query need to display id 4 (still remain with 26) and id 5 (
still remain with 60)
Can someone help me on this query?
Sample Purchase Order table
id date item_code quantity
-- -- -- --
1 2005-01-02 item_A 80
2 2005-01-15 item_A 23
3 2005-02-04 item_A 43
4 2005-02-23 item_A 30
5 2005-03-13 item_A 60
Thanks in advance,
Kriste|||hi
you can easly turn it to a sp
declare @.salessum int
declare @.id int,@.quantity int
declare unsold cursor for
select id, quantity
from porders
order by id
open unsold
declare @.sum int
set @.sum=0
set @.salessum=150
fetch next from unsold
into @.id,@.quantity
WHILE @.sum<=@.salessum
BEGIN
set @.sum=@.sum+@.quantity
FETCH NEXT FROM unsold
INTO @.id,@.quantity
END
CLOSE unsold
DEALLOCATE unsold
set @.sum=@.sum-@.salessum
set @.id=@.id-1
select id,date,item_code,@.sum as remain from porders where id=@.id
union all
select id,date,item_code,quantity as remain from porders where id>@.id
"Kriste L" wrote:

> Hi Everybody,
> I've provide a sample Purchase Order with some data. I need to maintain a
FIFO (first-in-first-out) for the the sale of item and at the end of the day
, will generate a report which are the Purchase Order with item still unsold
.
> Example, sold 150 items (80 from id=1, 23 from id=2, 43 from id=3 and 4 fr
om id=4) , so the query need to display id 4 (still remain with 26) and id 5
(still remain with 60)
> Can someone help me on this query?
> Sample Purchase Order table
> id date item_code quantity
> -- -- -- --
> 1 2005-01-02 item_A 80
> 2 2005-01-15 item_A 23
> 3 2005-02-04 item_A 43
> 4 2005-02-23 item_A 30
> 5 2005-03-13 item_A 60
> Thanks in advance,
> Kriste
>|||previous code i send may couse problems sorry:(
this is much better and safe:)
declare @.salessum int
declare @.id int,@.quantity int
declare unsold cursor for
select id, quantity
from porders
order by id
open unsold
declare @.sum int
set @.sum=0
set @.salessum=150
fetch next from unsold
into @.id,@.quantity
WHILE @.@.fetch_status=0
BEGIN
set @.sum=@.sum+@.quantity
if @.sum>@.salessum
begin
set @.sum=@.sum-@.salessum
select id,date,item_code,@.sum as remain from porders where id=@.id
union all
select id,date,item_code,quantity as remain from porders where id>@.id
end
else
FETCH NEXT FROM unsold
INTO @.id,@.quantity
END
CLOSE unsold
DEALLOCATE unsold
"POKEMON" wrote:
> hi
> you can easly turn it to a sp
> declare @.salessum int
> declare @.id int,@.quantity int
> declare unsold cursor for
> select id, quantity
> from porders
> order by id
> open unsold
> declare @.sum int
> set @.sum=0
> set @.salessum=150
> fetch next from unsold
> into @.id,@.quantity
> WHILE @.sum<=@.salessum
> BEGIN
> set @.sum=@.sum+@.quantity
> FETCH NEXT FROM unsold
> INTO @.id,@.quantity
> END
> CLOSE unsold
> DEALLOCATE unsold
>
> set @.sum=@.sum-@.salessum
> set @.id=@.id-1
> select id,date,item_code,@.sum as remain from porders where id=@.id
> union all
> select id,date,item_code,quantity as remain from porders where id>@.id
> "Kriste L" wrote:
>

Thursday, February 16, 2012

Calculation based on total at Table footer (eg. % of report total)

Hi!
I have data on a report where I am subtotalling by Items on an invoice. So,
my subtotal has the sum of all the invoices for that item.
I also want to do a calculation that will calculate for each item (that is
summarized) % of total sale for all items. Presently, my totals for all items
are in the Table Footer.
Item Amount Percent of Total
A 10 (subtotal) 10/15 =67%(ie divided by report
total)
B 5 (subtotal) 5/15 =33%
Report Total = 15
How do I do this?
Thanks
Ranjit CharlesHi,
You need to have a report variable which stores the grand total already or a
select statement which stores the grand total. Then you can use this variable
to find out the percentage. You can have a dataset created for this select
alone which will find out the grand total and use the dataset for percentage.
Regards
Amarnath
"Ranjit Charles" wrote:
> Hi!
> I have data on a report where I am subtotalling by Items on an invoice. So,
> my subtotal has the sum of all the invoices for that item.
> I also want to do a calculation that will calculate for each item (that is
> summarized) % of total sale for all items. Presently, my totals for all items
> are in the Table Footer.
> Item Amount Percent of Total
> A 10 (subtotal) 10/15 =67%(ie divided by report
> total)
> B 5 (subtotal) 5/15 =33%
> Report Total = 15
> How do I do this?
> Thanks
> Ranjit Charles|||Or you can sum the total amount and put it in to a new value field for the
select statement...
e.g. select *, (select sum() ... from ...) "GrandTotal" from ...
which obviously means you calculate the total for every line but SQL is
pretty efficient.
Craig
"Amarnath" <Amarnath@.discussions.microsoft.com> wrote in message
news:4977EB5C-C4A7-4109-B61E-F3D9B059DE28@.microsoft.com...
> Hi,
> You need to have a report variable which stores the grand total already or
> a
> select statement which stores the grand total. Then you can use this
> variable
> to find out the percentage. You can have a dataset created for this select
> alone which will find out the grand total and use the dataset for
> percentage.
> Regards
> Amarnath
>
> "Ranjit Charles" wrote:
>> Hi!
>> I have data on a report where I am subtotalling by Items on an invoice.
>> So,
>> my subtotal has the sum of all the invoices for that item.
>> I also want to do a calculation that will calculate for each item (that
>> is
>> summarized) % of total sale for all items. Presently, my totals for all
>> items
>> are in the Table Footer.
>> Item Amount Percent of Total
>> A 10 (subtotal) 10/15 =67%(ie divided by report
>> total)
>> B 5 (subtotal) 5/15 =33%
>> Report Total = 15
>> How do I do this?
>> Thanks
>> Ranjit Charles

Calculating Totals

Hi,
I have a query that shows an item that can have multiple rows of data
associated with it.
ITEM PRICE QTY_on_BO EXT PRICE PO No. QTY on PO
12345 36 3 108 2589
10
12345 36 3 108 8965
7
12345 36 3 108 4563
5
78945 20 5 100 1258
11
78945 20 5 100 9632
4
I am trying to total the QTY_on_BO column. The issue is that I only need to
sum (3+5 = 8) not (3+3+3+5+5 =19). Same thing with the column EXT_Price, I
only need to sum (108+100=208) not (108+108+108+100+100=524).
I would appreciate any help you could provide.
Thanks,
Kevin
P.S. here is my query:
SELECT va.item, i.description, v.vendor_name, va.buyer_code,
va.cost_amt, va.purchase_order, va.due_date, dbo.SKU.list_price_amt,
COALESCE
((SELECT SUM(order_qty -
original_reserve_qty - cancel_qty - shipped_qty) AS Expr1
FROM dbo.ORDER_DETAIL AS od
WHERE (order_type IN ('E', 'P')) AND
(order_qty - original_reserve_qty - cancel_qty - shipped_qty > 0) AND
(item_class NOT IN ('995', '998', '999'))
AND (item = va.item)),
0) AS BOQuantity, COALESCE
((SELECT SUM(order_qty -
original_reserve_qty - cancel_qty - shipped_qty) AS Expr1
FROM dbo.ORDER_DETAIL AS od
WHERE (order_type IN ('E', 'P')) AND
(order_qty - original_reserve_qty - cancel_qty - shipped_qty > 0) AND
(item_class NOT IN ('995', '998', '999'))
AND (item = va.item)),
0) * dbo.SKU.list_price_amt AS ext_bo_retail, va.qty AS PO_QTY
FROM dbo.VENDOR_ACTIVITY AS va INNER JOIN
dbo.ITEM AS i ON va.item = i.item INNER JOIN
dbo.VENDOR AS v ON va.vendor_key = v.vendor_key INNER
JOIN
dbo.SKU ON i.item = dbo.SKU.item CROSS JOIN
dbo.ORDER_DETAIL
WHERE (va.due_date > '2008-03-25')
GROUP BY va.item, i.description, va.buyer_code, va.cost_amt, va.due_date,
v.vendor_name, va.purchase_order, dbo.SKU.list_price_amt, va.qty
HAVING (COALESCE
((SELECT SUM(order_qty -
original_reserve_qty - cancel_qty - shipped_qty) AS Expr1
FROM dbo.ORDER_DETAIL AS od
WHERE (order_type IN ('E', 'P')) AND
(order_qty - original_reserve_qty - cancel_qty - shipped_qty > 0) AND
(item_class NOT IN ('995,''998', '999'))
AND (item = va.item)),
0) > 0)
ORDER BY COALESCE
((SELECT SUM(order_qty -
original_reserve_qty - cancel_qty - shipped_qty) AS Expr1
FROM dbo.ORDER_DETAIL AS od
WHERE (order_type IN ('E', 'P')) AND
(order_qty - original_reserve_qty - cancel_qty - shipped_qty > 0) AND
(item_class NOT IN ('995', '998', '999'))
AND (item = va.item)),
0) * dbo.SKU.list_price_amt DESC, va.due_dateI really could use some help with this.
Still trying to figure this out, but everytime I sum I get a sum of all the
contents of the cells instead of a sum of by item.
Please help if you can.
Thanks,
Kevin
"Kevin Eck" <keck@.titlenine.com> wrote in message
news:Olyzp$PkIHA.4120@.TK2MSFTNGP06.phx.gbl...
> Hi,
> I have a query that shows an item that can have multiple rows of data
> associated with it.
> ITEM PRICE QTY_on_BO EXT PRICE PO No. QTY on PO
> 12345 36 3 108
> 2589 10
> 12345 36 3 108
> 8965 7
> 12345 36 3 108
> 4563 5
> 78945 20 5 100
> 1258 11
> 78945 20 5 100
> 9632 4
> I am trying to total the QTY_on_BO column. The issue is that I only need
> to sum (3+5 = 8) not (3+3+3+5+5 =19). Same thing with the column
> EXT_Price, I only need to sum (108+100=208) not (108+108+108+100+100=524).
> I would appreciate any help you could provide.
> Thanks,
> Kevin
> P.S. here is my query:
> SELECT va.item, i.description, v.vendor_name, va.buyer_code,
> va.cost_amt, va.purchase_order, va.due_date, dbo.SKU.list_price_amt,
> COALESCE
> ((SELECT SUM(order_qty -
> original_reserve_qty - cancel_qty - shipped_qty) AS Expr1
> FROM dbo.ORDER_DETAIL AS od
> WHERE (order_type IN ('E', 'P')) AND
> (order_qty - original_reserve_qty - cancel_qty - shipped_qty > 0) AND
> (item_class NOT IN ('995', '998', '999'))
> AND (item = va.item)),
> 0) AS BOQuantity, COALESCE
> ((SELECT SUM(order_qty -
> original_reserve_qty - cancel_qty - shipped_qty) AS Expr1
> FROM dbo.ORDER_DETAIL AS od
> WHERE (order_type IN ('E', 'P')) AND
> (order_qty - original_reserve_qty - cancel_qty - shipped_qty > 0) AND
> (item_class NOT IN ('995', '998', '999'))
> AND (item = va.item)),
> 0) * dbo.SKU.list_price_amt AS ext_bo_retail, va.qty AS PO_QTY
> FROM dbo.VENDOR_ACTIVITY AS va INNER JOIN
> dbo.ITEM AS i ON va.item = i.item INNER JOIN
> dbo.VENDOR AS v ON va.vendor_key = v.vendor_key INNER
> JOIN
> dbo.SKU ON i.item = dbo.SKU.item CROSS JOIN
> dbo.ORDER_DETAIL
> WHERE (va.due_date > '2008-03-25')
> GROUP BY va.item, i.description, va.buyer_code, va.cost_amt, va.due_date,
> v.vendor_name, va.purchase_order, dbo.SKU.list_price_amt, va.qty
> HAVING (COALESCE
> ((SELECT SUM(order_qty -
> original_reserve_qty - cancel_qty - shipped_qty) AS Expr1
> FROM dbo.ORDER_DETAIL AS od
> WHERE (order_type IN ('E', 'P')) AND
> (order_qty - original_reserve_qty - cancel_qty - shipped_qty > 0) AND
> (item_class NOT IN ('995,''998', '999'))
> AND (item = va.item)),
> 0) > 0)
> ORDER BY COALESCE
> ((SELECT SUM(order_qty -
> original_reserve_qty - cancel_qty - shipped_qty) AS Expr1
> FROM dbo.ORDER_DETAIL AS od
> WHERE (order_type IN ('E', 'P')) AND
> (order_qty - original_reserve_qty - cancel_qty - shipped_qty > 0) AND
> (item_class NOT IN ('995', '998', '999'))
> AND (item = va.item)),
> 0) * dbo.SKU.list_price_amt DESC, va.due_date
>
>
>|||Hi Kevin,
I've had this problem in the past and even though I came up with a solution
it is not very elegent. My solution was, for each group (e.g. your ITEM
group), extend the SQL to include a count of the number items in the group
(e.g. join (select Item, count(*) from ... group by Item) t on ...). Then
this count value can be used to divide down the overall total to get the
correct result.
I would mind coming up with a more elegent solution that perhaps uses the
scope functions (Sum(value, scope), Count(value, scope)) but I haven't
figured that out yet.
Regards,
Brian
"Kevin Eck" <keck@.titlenine.com> wrote in message
news:%23PEwzTdkIHA.748@.TK2MSFTNGP04.phx.gbl...
>I really could use some help with this.
> Still trying to figure this out, but everytime I sum I get a sum of all
> the contents of the cells instead of a sum of by item.
> Please help if you can.
> Thanks,
> Kevin
> "Kevin Eck" <keck@.titlenine.com> wrote in message
> news:Olyzp$PkIHA.4120@.TK2MSFTNGP06.phx.gbl...
>> Hi,
>> I have a query that shows an item that can have multiple rows of data
>> associated with it.
>> ITEM PRICE QTY_on_BO EXT PRICE PO No. QTY on PO
>> 12345 36 3 108 2589 10
>> 12345 36 3 108 8965 7
>> 12345 36 3 108 4563 5
>> 78945 20 5 100 1258 11
>> 78945 20 5 100 9632 4
>> I am trying to total the QTY_on_BO column. The issue is that I only need
>> to sum (3+5 = 8) not (3+3+3+5+5 =19). Same thing with the column
>> EXT_Price, I only need to sum (108+100=208) not
>> (108+108+108+100+100=524).
>> I would appreciate any help you could provide.
>> Thanks,
>> Kevin
>> P.S. here is my query:
>> SELECT va.item, i.description, v.vendor_name, va.buyer_code,
>> va.cost_amt, va.purchase_order, va.due_date, dbo.SKU.list_price_amt,
>> COALESCE
>> ((SELECT SUM(order_qty -
>> original_reserve_qty - cancel_qty - shipped_qty) AS Expr1
>> FROM dbo.ORDER_DETAIL AS od
>> WHERE (order_type IN ('E', 'P')) AND
>> (order_qty - original_reserve_qty - cancel_qty - shipped_qty > 0) AND
>> (item_class NOT IN ('995', '998', '999'))
>> AND (item =>> va.item)), 0) AS BOQuantity, COALESCE
>> ((SELECT SUM(order_qty -
>> original_reserve_qty - cancel_qty - shipped_qty) AS Expr1
>> FROM dbo.ORDER_DETAIL AS od
>> WHERE (order_type IN ('E', 'P')) AND
>> (order_qty - original_reserve_qty - cancel_qty - shipped_qty > 0) AND
>> (item_class NOT IN ('995', '998', '999'))
>> AND (item =>> va.item)), 0) * dbo.SKU.list_price_amt AS ext_bo_retail, va.qty AS PO_QTY
>> FROM dbo.VENDOR_ACTIVITY AS va INNER JOIN
>> dbo.ITEM AS i ON va.item = i.item INNER JOIN
>> dbo.VENDOR AS v ON va.vendor_key = v.vendor_key
>> INNER JOIN
>> dbo.SKU ON i.item = dbo.SKU.item CROSS JOIN
>> dbo.ORDER_DETAIL
>> WHERE (va.due_date > '2008-03-25')
>> GROUP BY va.item, i.description, va.buyer_code, va.cost_amt, va.due_date,
>> v.vendor_name, va.purchase_order, dbo.SKU.list_price_amt, va.qty
>> HAVING (COALESCE
>> ((SELECT SUM(order_qty -
>> original_reserve_qty - cancel_qty - shipped_qty) AS Expr1
>> FROM dbo.ORDER_DETAIL AS od
>> WHERE (order_type IN ('E', 'P')) AND
>> (order_qty - original_reserve_qty - cancel_qty - shipped_qty > 0) AND
>> (item_class NOT IN ('995,''998', '999'))
>> AND (item = va.item)),
>> 0) > 0)
>> ORDER BY COALESCE
>> ((SELECT SUM(order_qty -
>> original_reserve_qty - cancel_qty - shipped_qty) AS Expr1
>> FROM dbo.ORDER_DETAIL AS od
>> WHERE (order_type IN ('E', 'P')) AND
>> (order_qty - original_reserve_qty - cancel_qty - shipped_qty > 0) AND
>> (item_class NOT IN ('995', '998', '999'))
>> AND (item =>> va.item)), 0) * dbo.SKU.list_price_amt DESC, va.due_date
>>
>>
>>
>|||Found a simple solution to this: divide the price or quantity by "count(*)
over(partition by item)"
"Brian" <brian1taylor@.hotmail.com> wrote in message
news:%23cJovqFoIHA.2632@.TK2MSFTNGP04.phx.gbl...
> Hi Kevin,
> I've had this problem in the past and even though I came up with a
> solution it is not very elegent. My solution was, for each group (e.g.
> your ITEM group), extend the SQL to include a count of the number items in
> the group (e.g. join (select Item, count(*) from ... group by Item) t on
> ...). Then this count value can be used to divide down the overall total
> to get the correct result.
> I would mind coming up with a more elegent solution that perhaps uses the
> scope functions (Sum(value, scope), Count(value, scope)) but I haven't
> figured that out yet.
> Regards,
> Brian
> "Kevin Eck" <keck@.titlenine.com> wrote in message
> news:%23PEwzTdkIHA.748@.TK2MSFTNGP04.phx.gbl...
>>I really could use some help with this.
>> Still trying to figure this out, but everytime I sum I get a sum of all
>> the contents of the cells instead of a sum of by item.
>> Please help if you can.
>> Thanks,
>> Kevin
>> "Kevin Eck" <keck@.titlenine.com> wrote in message
>> news:Olyzp$PkIHA.4120@.TK2MSFTNGP06.phx.gbl...
>> Hi,
>> I have a query that shows an item that can have multiple rows of data
>> associated with it.
>> ITEM PRICE QTY_on_BO EXT PRICE PO No. QTY on PO
>> 12345 36 3 108 2589 10
>> 12345 36 3 108 8965 7
>> 12345 36 3 108 4563 5
>> 78945 20 5 100 1258 11
>> 78945 20 5 100 9632 4
>> I am trying to total the QTY_on_BO column. The issue is that I only
>> need to sum (3+5 = 8) not (3+3+3+5+5 =19). Same thing with the column
>> EXT_Price, I only need to sum (108+100=208) not
>> (108+108+108+100+100=524).
>> I would appreciate any help you could provide.
>> Thanks,
>> Kevin
>> P.S. here is my query:
>> SELECT va.item, i.description, v.vendor_name, va.buyer_code,
>> va.cost_amt, va.purchase_order, va.due_date, dbo.SKU.list_price_amt,
>> COALESCE
>> ((SELECT SUM(order_qty -
>> original_reserve_qty - cancel_qty - shipped_qty) AS Expr1
>> FROM dbo.ORDER_DETAIL AS od
>> WHERE (order_type IN ('E', 'P')) AND
>> (order_qty - original_reserve_qty - cancel_qty - shipped_qty > 0) AND
>> (item_class NOT IN ('995', '998', '999'))
>> AND (item =>> va.item)), 0) AS BOQuantity, COALESCE
>> ((SELECT SUM(order_qty -
>> original_reserve_qty - cancel_qty - shipped_qty) AS Expr1
>> FROM dbo.ORDER_DETAIL AS od
>> WHERE (order_type IN ('E', 'P')) AND
>> (order_qty - original_reserve_qty - cancel_qty - shipped_qty > 0) AND
>> (item_class NOT IN ('995', '998', '999'))
>> AND (item =>> va.item)), 0) * dbo.SKU.list_price_amt AS ext_bo_retail, va.qty AS
>> PO_QTY
>> FROM dbo.VENDOR_ACTIVITY AS va INNER JOIN
>> dbo.ITEM AS i ON va.item = i.item INNER JOIN
>> dbo.VENDOR AS v ON va.vendor_key = v.vendor_key
>> INNER JOIN
>> dbo.SKU ON i.item = dbo.SKU.item CROSS JOIN
>> dbo.ORDER_DETAIL
>> WHERE (va.due_date > '2008-03-25')
>> GROUP BY va.item, i.description, va.buyer_code, va.cost_amt,
>> va.due_date, v.vendor_name, va.purchase_order, dbo.SKU.list_price_amt,
>> va.qty
>> HAVING (COALESCE
>> ((SELECT SUM(order_qty -
>> original_reserve_qty - cancel_qty - shipped_qty) AS Expr1
>> FROM dbo.ORDER_DETAIL AS od
>> WHERE (order_type IN ('E', 'P')) AND
>> (order_qty - original_reserve_qty - cancel_qty - shipped_qty > 0) AND
>> (item_class NOT IN ('995,''998', '999'))
>> AND (item =>> va.item)), 0) > 0)
>> ORDER BY COALESCE
>> ((SELECT SUM(order_qty -
>> original_reserve_qty - cancel_qty - shipped_qty) AS Expr1
>> FROM dbo.ORDER_DETAIL AS od
>> WHERE (order_type IN ('E', 'P')) AND
>> (order_qty - original_reserve_qty - cancel_qty - shipped_qty > 0) AND
>> (item_class NOT IN ('995', '998', '999'))
>> AND (item =>> va.item)), 0) * dbo.SKU.list_price_amt DESC, va.due_date
>>
>>
>>
>>
>

Sunday, February 12, 2012

Calculating AVG Values

Hi mates,


Code Snippet

WITH
MEMBER [MEASURES].X AS AVG([MEASURES].[ITEM VALUE])
MEMBER MEASURES.PARENTID

AS [DEPARTMENT].DEPARTMENTS].CURRENTMEMBER.PARENT.NAME

MEMBER MEASURES.CHILDRENID AS
GENERATE(DESCENDANTS([DEPARTMENT].[DEPARTMENTS].CURRENTMEMBER),
[DEPARTMENT].[DEPARTMENTS].CURRENTMEMBER.NAME, " - ")
MEMBER MEASURES.CHILDRENNAME AS
GENERATE(DESCENDANTS([DEPARTMENT].[DEPARTMENT].CURRENTMEMBER),
[DEPARTMENT].[DEPARTMENT].CURRENTMEMBER.NAME, " - ")
SELECT
CROSSJOIN([TIME].YEAR.&[2006], [TIME].[DATEHIER].[MONTH].MEMBERS,
DESCENDANTS([DEPARTMENT].[2],
[DEPARTMENT].[DEPARTMENTS].CURRENTMEMBER, SELF_AND_BEFORE)) ON ROWS ,

{(MEASURES.PARENTID), (MEASURES.CHILDRENID), (MEASURES.CHILDRENNAME),

[MEASURES].X} ON COLUMNS

FROM OLAPDEV
WHERE ([ITEM].[78])

this MDX Query returns the following result


Year
Month
Department
Department ParentId
Department ChildrenIds
Department ChildrenNames
ItemValue (Measure Value)

This returns sum of Item value for each month,year and deparmemnt.

But I need Avg of Item Values for each month, year and department

please help me


thanks

anand

You have an "Item Value" measure defined. Add another measure which is the Count aggregate function instead of the Sum aggregate function. Now that you have the Sum and the Count, you can simply do Sum/Count and calculate the average. So your MDX would start like the following:

WITH
MEMBER [MEASURES].X AS IIf(IsEmpty([MEASURES].[ITEM VALUE COUNT]),null,[MEASURES].[ITEM VALUE]/[MEASURES].[ITEM VALUE COUNT])

|||

It is not returning the correct value,

could not get count for each year, month and by department.

count to be calculated , using group of year, month and department,

but by above solution i couldn't get that

|||You're going to need to give us more info if you want our help. We can't read your mind. What precisely is wrong? What is the correct value? What is currently being returned?|||

Code Snippet

WITH

MEMBER [MEASURES].X AS [MEASURES].[ITEM VALUE]

MEMBER MEASURES.PARENTID AS

[DEPARTMENT].[DEPARTMENTS].CURRENTMEMBER.PARENT.NAME MEMBER

MEASURES.CHILDRENID AS

GENERATE(DESCENDANTS([DEPARTMENT].[DEPARTMENTS].CURRENTMEMBER),

[DEPARTMENT].[DEPARTMENTS].CURRENTMEMBER.NAME, " - ")

MEMBER MEASURES.CHILDRENNAME AS

GENERATE(DESCENDANTS([DEPARTMENT].[DEPARTMENT].CURRENTMEMBER),

[DEPARTMENT].[DEPARTMENT].CURRENTMEMBER.NAME, " - ")

SELECT

CROSSJOIN([TIME].YEAR.&[2006],

[TIME].[DATEHIER].[MONTH].MEMBERS,

DESCENDANTS([DEPARTMENT].[2],

[DEPARTMENT].[DEPARTMENTS].CURRENTMEMBER, SELF_AND_BEFORE)) ON ROWS ,

{(MEASURES.PARENTID), (MEASURES.CHILDRENID),

(MEASURES.CHILDRENNAME), [MEASURES].X} ON COLUMNS

FROM IBMTEST

WHERE ([ITEM].[78])

above query returns following results, which returns sum of itemvalue group by year, month, department.

Year #Month #Department #Parent.Dept #Child.deptIDs #Child.DeptNames #Value

2006 1 2 2 2 All - Corporate 337710

2006 2 2 2 2 All - Corporate 328059

2006 3 2 2 2 All - Corporate 432346

2006 4 2 2 2 All - Corporate 342362

2006 5 2 2 2 All - Corporate (null)


my requirement is avg(itemvalue) group by year, month and department.

WITH
MEMBER [MEASURES].X AS IIf(IsEmpty([MEASURES].[ITEM VALUE COUNT]),null,[MEASURES].[ITEM VALUE]/[MEASURES].[ITEM VALUE COUNT])

if i use your above calculated member it gives error for using item [MEASURES].[ITEM VALUE COUNT],

WITH
MEMBER [MEASURES].X AS IIf(IsEmpty( COUNT([MEASURES].[ITEM VALUE])),null,[MEASURES].[ITEM VALUE]/ COUNT([MEASURES].[ITEM VALUE]))

i removed count and used count(measures.itemvalue), this is also returing the same value as sum. even using AVG(MEASURES.ITEMVLAUE) also not

working.

i think this is not working out since crossjoin is used. i hope this is more clear to u.