How to divide/distribute Total count of each item to defined parts
sorry if subject of my question is not clear what i mean, i had problem for defining subject for this question.
I have a list that shows how many books we have for each PO No. (Sorted by PO No.) Like below:
now i would like to to divide/distribute books to boxes.
books have book no for each po no. for example if we have for po-0001 , TOTAL books=12, i mean we have different books from book no 1 of 12 until 12 of 12
LIST 1:
PO No
TOTAL BOOKS
PO-0001
12
PO-0002
15
PO-0003
26
Now I would like to distribute/divide these books to boxes and each box gets maximum 10 books. Like below list
LIST 2:
BOX NO
BOOKS
PO NO
0001
BOOK 1~10 PO-0001
0002
BOOK 11~12 PO-0001
0002
BOOK 1~8
PO-0002
0003
BOOK 9~15 PO-0002
0003
BOOK 1~3
PO-0003
0004
BOOK 4~13 PO-0003
0005
BOOK 14~23 PO-0003
format is not important in the list2, for example in Box 0002 we have these items like below book 11~12 means (book 11 of 12 +book 12 of 12) in po-0001
+ book 1 of 15 until book 8 of 15) in po-0002
BOX NO
BOOKS
PO NO
0002
BOOK 11~12 PO-0001
0002
BOOK 1~8
PO-0002
Please help how I can produce automatically list 2 from list 1 by query or coding.
Thanks, your answer was very helpful for me but actually I would like “Box No” increased sequentially until capacity of box is full, even when put in one box , books from two or three “pono”.
Now “box no” starts from “1” when dividing “total books” of po no. is finished.
I mean when PONo, TotalBooks are like below:
PONo
TotalBooks
Po-0001
2
Po-0002
11
Po-0003
3
Po-0004
6
Your Query returns :
PONo
TotalBooks
CountOfBoxes
BoxNo
BooksPerBox
StartNo
EndNo
po-0001
2
1
1
2
1
2
po-0002
11
2
1
5
1
5
po-0002
11
2
2
6
6
11
po-0003
3
1
1
3
1
3
po-0004
6
1
1
6
1
6
I would like query returns like below:
PONo
TotalBooks
BoxNo
StartNo
EndNo
po-0001
2
1
1
2
po-0002
11
1
1
8
po-0002
11
2
9
11
po-0003
3
2
1
3
po-0004
6
2
1
4
po-0004
6
3
5
6
Similar Messages
-
Introduction
We need to loop through all the flat files that have the same structure in a folder and import all the data to a single SQL Server table. How can we obtain the total count of the rows inserted to the destination SQL Server table?
Solution
We can use Execute SQL Task or Script Task to aggregate the row count increment for each iteration of the Foreach Loop Container. The following steps are the preparations before we add the Execute SQL Task or Script Task:
Create a String type variable FilePath, two Int32 type variables InsertRowCnt and TotalRowCnt.
Drag a Foreach Loop Container to the Control Flow design surface, set the Enumerator to “Foreach File Enumerator”, specify the source folder and the files extension, and set the “Retrieve file name” option to “Fully qualified”.
On the “Variable Mappings” tab of the container, map the variable FilePath to the collection value.
Drag a Data Flow Task to the container, in the Data Flow Task, add a Flat File Source, a Row Count Transformation, and an OLE DB Destination, and join them. Create a Flat File Connection Manager to connect to one of the flat files, and then configure the
Flat File Source as well as the OLE DB Destination adapter. Set the variable for the Row Count Transformation to “User::InsertRowCnt”.
Open the Property Expressions Editor for the Flat File Connection Manager, and set the expression of “ConnectionString” property to
“@[User::FilePath]”.
(I) Execute SQL Task Method:
In the Control Flow, drag an Execute SQL Task under the Data Flow Task and join them.
Create one or using any one existing OLE DB Connection Manager for the Execute SQL Task, set the “ResultSet” option to “Single row”, and then set the “SQLStatement” property to:
DECLARE @InsertRowCnt INT,
@TotalRowCnt INT
SET @InsertRowCnt=?
SET @TotalRowCnt=?
SET @TotalRowCnt=@InsertRowCnt+@TotalRowCnt
SELECT TotalRowCnt=@TotalRowCnt
On to parameter 1.
On the “Result Set” tab of the Execute SQL Task, map result 0 to variable “User::TotalRowCnt”.
(II) Script Task Method:
In the Control Flow, drag a Script Task under the Data Flow Task and join them.
In the Script Task, select variable InsertRowCnt for “ReadOnlyVariables” option, and select variable TotalRowCnt for “ReadWriteVariables”.
Edit the Main method as follows (C#):
public void Main()
// TODO: Add your code here
int InsertRowCnt = Convert.ToInt32(Dts.Variables["User::InsertRowCnt"].Value.ToString()
int TotalRowCnt = Convert.ToInt32(Dts.Variables["User::TotalRowCnt"].Value.ToString());
TotalRowCnt = TotalRowCnt + InsertRowCnt;
Dts.Variables["User::InsertRowCnt"].Value = TotalRowCnt;
Dts.TaskResult = (int)ScriptResults.Success;
Or (VB)
Public Sub Main()
' Add your code here
Dim InsertRowCnt As Integer =
Convert.ToInt32(Dts.Variables("User::InsertRowCnt").Value.ToString())
Dim TotalRowCnt As Integer =
Convert.ToInt32(Dts.Variables("User::TotalRowCnt").Value.ToString())
TotalRowCnt = TotalRowCnt + InsertRowCnt
Dts.Variables("User::TotalRowCnt").Value = TotalRowCnt
Dts.TaskResult = ScriptResults.Success
End Sub
Applies to
Microsoft SQL Server 2005
Microsoft SQL Server 2008
Microsoft SQL Server 2008 R2
Microsoft SQL Server 2012
Microsoft SQL Server 2014
Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.Hi ITBobbyP,
If I understand correctly, you want to load data from multiple sheets in an .xlsx file into a SQL Server table.
If in this scenario, please refer to the following tips:
The Foreach Loop container should be configured as shown below:
Enumerator: Foreach ADO.NET Schema Rowset Enumerator
Connection String: The OLE DB Connection String for the excel file.
Schema: Tables.
In the Variable Mapping, map the variable to Sheet_Name, and change the Index from 0 to 2.
The connection string for Excel Connection Manager is the original one, we needn’t make any change.
Change Table Name or View name to the variable Sheet_Name.
If you want to load data from multiple sheets in multiple .xlsx files into a SQL Server table, please refer to following thread:
http://stackoverflow.com/questions/7411741/how-to-loop-through-excel-files-and-load-them-into-a-database-using-ssis-package
Thanks,
Katherine Xiong
Katherine Xiong
TechNet Community Support -
Help in finding the total count for each month
Hello everyone,
Sometime back I had posted about the date function. I have that problem solved now my problem is that after finding all records which against each record I need to find the total count for that month if no records than I have to set it to a 0.
Here is how my program has been written.
PROCEDURE extract_materials
IS
CURSOR xyz
BEGIN
FOR xyz1 IN xyz LOOP
-- once inside the loop for each of the record from
the cursor I need to find a total count for that record for everymonth in the year.
All these records will be instered in to a staging table
Can you please help me out with this. I really appreciate this.
Thanks in advance.
-VaniAndrew - you missed the tricky bit of the spec - include missing months with a zero.
You need to do an outer join to a select from any big table with a function involving rownum and add_months to generate all the possible months. However, its time to go home and I can't be bothered to work out the finer details. -
How to create a background image for each item in a List object
Hello.
I am trying to create a background image that displays whenever a user posts something to a list. For example when a user posts text it would appear in a list. The new item in the list would contain a specific background image with the users text appearing on top of the background image. I do not want a background image for the entire list, rather each item within the list.
I am not sure how clear this is so I added an image below. When a user enters text in and clicks the "post-it" button their text would appear below with the sticky note background.
I am not sure which list type would be best for this problem or how to create insert the image, so I am open to suggestions.
Thank you for your help. Any advice or guidance will be greatly appreciated!Hi
the easiest way would be with itemRenderer.
You have to do two things:
1. In your list declaration use a item renderer: <mx:List itemRenderer="myRenderer"/>
2. create a flex component myRenderer that will be the single item. This can be a canvas with a background image and a text field on it.
When you add a new item to the list, a new myRenderer item will be created and the data property will be passed to it. So you have to put "data" in your textField.
If you need more help try looking at Tour de Flex samples, they're pretty easy.
Andrei -
How to find out Address no for each item
Hi All,
how to find out address no (ADRNR) for each item in the PO (ME23N).
will it created by automatically or mannually?
Please Very urgent.
Thanks,
Subbu.Hey Subbu,
We meet again
check
table EKPO
for each line item for a particular PO
there u have adrnr.
This is the address number for each line item -
How can I have individual count of each branch?
Hi,
I need to write a query for the following scenario.
For ex: Reliance is a company which is has diffenect branches under city1, city2, city3.
under city1 we have different regions like reg1, reg2, reg3. Under city2 we have reg4, reg5. Similarly under city3 we have reg7, reg8, reg9. Under each region we have got 2 participants like reg1 - p1, p2 reg2- p3, p3 and so on under each region.
I need to write a query such that i can have a count of number of participants under each city. My output should be like city1 - 6 city2 4 and so on.
Can any one help me out in this???
Thanks in advanceFor eg
CITY REGION PARTICIPANT
C1 R1 P1
C1 R1 P2
C1 R2 P3
C1 R2 P4
C2 R3 P5
C2 R3 P6
Output is as follows
CITY COUNT(3)
C1 4
C2 2
SQL Query
with reg_data as
((select 'C1' City,'R1' Region,'P1' Participant from dual) union all
(select 'C1' City,'R1' Region,'P2' Participant from dual) union all
(select 'C1' City,'R2' Region,'P3' Participant from dual) union all
(select 'C1' City,'R2' Region,'P4' Participant from dual) union all
(select 'C2' City,'R3' Region,'P5' Participant from dual) union all
(select 'C2' City,'R3' Region,'P6' Participant from dual))
select City,count(3) from reg_data
group by City -
How to get the total count of the no. or rows a cursor has fetched
Hi All,
Is there a way to get the number of rows a cursor query has fetched, without looping into the cursor and using a counter variable
I mean like in pl/sql table we can directly use the pl/sql table attribute .count is there a way to achieve this in cursor
thanks a lot in advanceQwerty wrote:
Is there a way to get the number of rows a cursor query has fetched, without looping into the cursor and using a counter variableYes.
It is zero.
On the first loop and first fetch it will be 1, second 2 etc.
This is because cursors have no rows, or fetch no rows until your code or the client uses the cursor to fetch them.
I mean like in pl/sql table we can directly use the pl/sql table attributeA PL/SQL array is not like a cursor, a PL/SQL array has the rows already fetched into it.
A cursor is not an array but a pointer to a compiled SQL statement so you cannot count how many rows it has, because it has none. You can only count how many rows you fetch from it. -
How can I calculate the count of each row and they are grouped in each mth?
hi, I need help on a database question. How can I count the number of record grouped by the last 12 months? I don't know any way to iterate the month one by one so that it return a table like this:
table_item
id item
1 A
2 B
3 C
4 D
table_record
item date
A 2006-01-01
A 2006-01-01
A 2006-01-01
B 2006-02-01
A 2006-03-01
C 2006-04-01
A 2006-04-01
D 2006-05-01
A 2006-05-01
A 2006-12-01
and I need a query to output following table:
item_count_in_2006
item 06-01 06-02 06-03 06-04 06-05 06-06 06-07 06-08 06-09 06-10 06-11 06-12
A 3 1 1
B 1
C 1
D 1
I tried so many way to do it.. I think SQL can't even product a table like that. Please give me some comments.
Thanks!select c1,
count(decode(to_char(c2,'YYYYMM'),'200601',1)) "200601",
count(decode(to_char(c2,'YYYYMM'),'200602',1)) "200602",
count(decode(to_char(c2,'YYYYMM'),'200603',1)) "200603",
count(decode(to_char(c2,'YYYYMM'),'200604',1)) "200604",
count(decode(to_char(c2,'YYYYMM'),'200605',1)) "200605",
count(decode(to_char(c2,'YYYYMM'),'200606',1)) "200606",
count(decode(to_char(c2,'YYYYMM'),'200607',1)) "200607",
count(decode(to_char(c2,'YYYYMM'),'200608',1)) "200608",
count(decode(to_char(c2,'YYYYMM'),'200608',1)) "200609",
count(decode(to_char(c2,'YYYYMM'),'200610',1)) "200610",
count(decode(to_char(c2,'YYYYMM'),'200611',1)) "200611",
count(decode(to_char(c2,'YYYYMM'),'200612',1)) "200612"
from tbl
group by c1
C 200601 200602 200603 200604 200605 200606 200607 200608 200609 200610
D 0 0 0 0 1 0 0 0 0 0 0 0
A 3 0 1 1 1 0 0 0 0 0 0 1
B 0 1 0 0 0 0 0 0 0 0 0 0
C 0 0 0 1 0 0 0 0 0 0 0 0Nicolas. -
How to specify a unique integer for each local variable defined in TestStand?
I have a .net application that reads all TestStand local variables, but for the .net application each local variable should have a unique integer number. Iterating through the locals and storing the index is not a good solution, because if a local variable is moved or deleted, the index will change.
Does anyone know how to do this in TestStand or having an idea how to this in my .net application?
Thanks.Thanks Doug for your reply. Using a GUID is not an option because this ID is too long. I will try to explain why I need this ID for. I have a lot of C# code that generates code to deal with a lot of instruments. For example to configure a device, user defined variables can be used to specify some settings or to store results. These variables are not stored in the generated code with a name but with an integer number. Now I want to try to be use all our existing device driver code with the TestStand sequencer. So, I need a translation between the name of a TestStand local variable and an integer number. After constructing the interface to my code I want to read all the variables from TestStand and now I need the integer ID to do the mapping to my variables. I know that I can use use your proposition 2 by encoding the unique ID into the name of the variable and parse the name of the variable to get it back, but this is not an automated way. This will be rather difficult if there are several hundreds of variables. For this reason I am looking for an alternative way. Looking forward for your response. Best regards
-
I'm trying to get the count for each row to total count for each month
Something like this
Hardware | Jan
Monitors | 5
Processors | 137
Printers | 57
etc........
How can I write a query for this. I can get the Hardware column but don't know how to get the next column.If you can provide more data like sample input DML statements it would have been wonderful..
Assuming is , you need a pivot. Here is an article on basic Pivot..
http://sqlsaga.com/sql-server/how-to-use-pivot-to-transform-rows-into-columns-in-sql-server/
something like this may be..
DECLARE @Input TABLE
Hardware VARCHAR(20),
[Date] VARCHAR(20)
INSERT INTO @Input VALUES('Monitor', '01/01/2014'), ('CPU', '01/01/2014'), ('Monitor', '01/03/2014')
, ('ABC', '01/01/2014'),('Monitor', '02/01/2014')
;WITH CTE AS
SELECT Hardware, LEFT(DATENAME(M, [Date]),3) AS [MonthName] FROM @Input
SELECT *
FROM
SELECT Hardware, [MonthName], COUNT(Hardware) AS Count FROM CTE GROUP BY Hardware, [MonthName]) a
PIVOT (MAX([Count]) FOR [MonthName] IN ([Jan], [Feb])) pvt
Please mark as answer, if this has helped you solve the issue.
Good Luck :) .. visit www.sqlsaga.com for more t-sql code snippets and BI related how to articles. -
I want to display total count on the top of a Column in business graphics
Hi All ,
How can I display total count of the column say for example no. of employees in a series of column chart type in business graphics.
Any type of help would be much appreciated.
Thanks
UdayHi Vishweshwara,
following is the code i wrote. please check the correctness of the code.
int seriescount = 0;
for(int i=0;i<nodesize;i++){
IGraphDataElement catele = gdNode.createGraphDataElement();
switch(i){
case 0:
if(wdContext.currentContextElement().getQ().equals("Q1")){
catele.setCategory("Q1");
catele.setKRA_Series1(Q1_KRA);
catele.setApp_Pln_Series2(Q1_AP);
catele.setRev_App_Series3(Q1_RA);
catele.setEnd_Rev_Series4(Q1_ERP);
catele.setApp_Procss_Series5(Q1_AIP);
catele.setApp_overall_Series6(Q1_AOP);
seriescount = seriescount+1; break;}
break;
case 1:
if(wdContext.currentContextElement().getQ().equals("Q2")){
catele.setCategory("Q2");
catele.setKRA_Series1(Q2_KRA);
catele.setApp_Pln_Series2(Q2_AP);
catele.setRev_App_Series3(Q2_RA);
catele.setEnd_Rev_Series4(Q2_ERP);
catele.setApp_Procss_Series5(Q2_AIP);
catele.setApp_overall_Series6(Q2_AOP);
seriescount = seriescount+1; break; }
break;
case 2:
if(wdContext.currentContextElement().getQ().equals("Q3")){
catele.setCategory("Q3");
catele.setKRA_Series1(Q3_KRA);
catele.setApp_Pln_Series2(Q3_AP);
catele.setRev_App_Series3(Q3_RA);
catele.setEnd_Rev_Series4(Q3_ERP);
catele.setApp_Procss_Series5(Q3_AIP);
catele.setApp_overall_Series6(Q3_AOP);
seriescount = seriescount+1; break;}
break;
case 3:
if(wdContext.currentContextElement().getQ().equals("Q4")){
catele.setCategory("Q4");
catele.setKRA_Series1(Q4_KRA);
catele.setApp_Pln_Series2(Q4_AP);
catele.setRev_App_Series3(Q4_RA);
catele.setEnd_Rev_Series4(Q4_ERP);
catele.setApp_Procss_Series5(Q4_AIP);
catele.setApp_overall_Series6(Q4_AOP);
seriescount = seriescount+1; break;}
break;
case 4: if(wdContext.currentContextElement().getQ().equals("All")){
wdContext.nodeGraphData().invalidate();
wdContext.currentContextElement().setGraphVisibility(WDVisibility.NONE);
wdThis.onActiondropdownaction(wdEvent);
}default:
wdContext.nodeGraphData().addElement(catele);
Thanks
Uday -
Fetching unit_of_meaurement value for each item
Hi ,.
I want to fetch the value unit_of_measurement (MSEHI) value from table T006
for each items
I havent find any linakage
How can i read these values for each item
Thanks
AnilI have a material number say, Grumpy. The report that I have shows the total sales for Grumpy for $13,000.00. Grumpy has other submaterials number says Grumpy_1, Grumpy_3, Grumpy_4, Grumpy_5. The report only shows the total quantity sold for each of these submaterials. Say
Grumpy_1 = 800
Grumpy_3 = 70
Grumpy_4 = 1
Grumpy_5 = 33
I want to find a way to get an IO that tells me a price sold for 1 quantity, so that I can use it to find the total sold for Grumpy_1, Grumpy_3, Grumpy_4, Grumpy_5 that will add to equal $13,000.00
Thanks
"<i>Sometimes I need what only you can provide: your absence.</i>" ~ Anonymous -
How can I display total playlist size in iTunes 11. It used to be visible for each playlist or CD, but I can't find it now.
The Friend: Thanks from me too for that super simple fix!! I feel kinda stupid for not knowing that.
Too bad Apple didn't:
Give it a more intuitive name than "Status Bar"... "status" is what is shown at the top of the window along with the Artist and Song Title, e.g.; how far into the song/podcast/video I've played and how much is left,
Put the keyboard commands in a more prominent place in their release notes when version 11 came out so we could more easily find the information they decided to hide in this attempt to make the desktop less cluttered and
Allow us the option of displaying the data size along with the song count and duration just beneath the playllist title. The status bar is a redundant listing of information except for the data size! Poorly conceived!
Perhaps Apple will remedy this in a future release. For those of us who like to burn our playlists to CD, DVD and even a thumb drive this information is essential. WIthout it, we're left to guess whether a given playlist will fit on our target device.
Thank you! -
How to get the total no.of fields count in TFS
How to check this:
You can define no more than 1,024 work item fields in the same team project collection, and you can set no more than 1,024 fields to
reportable in all team project collections.
I have created some new fields in my customized process template. How to get the field count to check this validation. Do we have any command for this since witadmin listfields does not give the total count info.
Thanks
DivyaHi Divya,
Thanks for your post.
Try to get fields count in collection using below code snippet:
TfsTeamProjectCollection tfs =
new
TfsTeamProjectCollection(new
Uri("collectionURL"));
tfs.EnsureAuthenticated();
WorkItemStore workitemstore = tfs.GetService<WorkItemStore>();
FieldDefinitionCollection fields = workitemstore.FieldDefinitions;
// get fields count in this collection
Console.WriteLine(fields.Count);
//get each field name
foreach(FieldDefinition
field in fields)
Console.WriteLine(field.Name);
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
How to get a total record count before grouping?
I need to group a report on a formula that does roughly the following:
[record count] / ( [total record count] / 20 )
What this acheives is to label each record with a number of 1 - 20 which I want to group on. Getting this figure is the easy part, what is not working is the fact that I cannot group from a formula that is calculated after grouping. I overcame a portion of this by using "Whilereadingrecords" (rather than "count", running totals, or while printing records) to acheive a record count.
I can't figure out how to get a total record count done before grouping. Is there a way to do this with "WhileReadingRecords"?? Is this even possible?
Thanks
JohnHi John,
The order of how Crystal does things dictates the order of which features you can use. Crystal has a two pass method. In the first pass it does things like passing the query, grouping, summarizing. In the second pass it does formulas, formatting, etc.
Unfortunately Crystal does the Grouping before summarizing so what you want to do can't be done in Crystal. The best way to get around this to either create a SQL Command or view/stored procedure that will do the summarizing for you. Then in the report you can use it.
Hope this helps,
Brian
Maybe you are looking for
-
Text preview size in PS 2014?
Hi, Installed PS CC 2014. Now my text preview size is back down to small and I can't seem to figure out how to change it back to a larger preview size. Any suggestions? Thanks! -Rowen
-
Flash Professional CS5 running very laggy on new pc
1st time asking a question here so please be patient with me if I'm asking in the wrong place. Basically I bought a new computer with Win 8 64-bit, AMD A8-6500 quad core @ 3.5ghz w/ Radeon onboard HD graphics, 8gb of RAM. My old laptop was an i5 with
-
Why can't I import my video from my memory card?
I have the sandisk ultra 16gb memory card and i film videos for youtube and recently when i have tried to import my longer videos like around 6 mins and longer loit says "iPhoto cannot import your photos because there was a problem downloading an ima
-
my battery for my 15 inc mac book pro is dying to quick
-
BB fault at Stonham exchange, Suffolk
Hi, I have had a problem with Broadband disconnecting every 10 minutes for the last few weeks, and after trying all the advice about connection issues (eg using the test socket, new hub, using ethernet instead of wireless) an engineer was finally sen