SQL: Add Values to Grouping Column
I am having a lot of Trouble with a Scenario that i think some of you might have come across.
(the whole Thing is about Business Trips, two tables, one filled with payments done on Business trips, and the other is about the Business Trips, so the first one has more Rows than the other, (there are more Payments that happened than Trips)) I have two
tables, Table A and Table B.
Table A Looks as follows
| TableA_ID | TableB_ID | PaymentMethod
| ValuePayed |
| 52 |
1
| Method1 |
23,2 |
| 21
| 1
| Method2
| 23,2 |
| 33
| 2
| Method3 |
23,2 |
| 42
| 1 | Method2 |
14
|
| 11 |
14
| Method1
| 267 |
| 42
| 1
| Method2
| 14,7 |
| 13
| 32
| Method1
| 100,2 |
Table B Looks like this
| TableB_ID | TravelExpenses
| OperatingExpense |
| 1
| 23
| 12
|
| 1
| 234
| 24
|
| 2
| 12
| 7
|
| 1
| 432
| 12
|
| 14
| 110
| 12
|
I am trying to create A measure Table (Table C) That Looks like like this:
| TableC_ID | TypeofCost
| Amount |
| 1
| Method1
| 100,2
|
| 2 | Method2
| 52 |
| 3 | TravelExpenses
| 7
|
| 4
| OperatingExpense|
12 |
| 5
| Method3
| 12
|
| 6 | OperatingExpense|
7 |
| 7
| Method3
| 12
|
(the Amount results are to be Summed and Columns - Employee, Month,
TypeofCost Grouped)
So i pretty much have to Group not only by the PaymentMethod which i get from table A, but Also insert new Values in the Group ('TravelExpenses' and 'OperatingExpense')
Can anybody give me any Idea about how this can be done in SQL ? i have been desperately trying for quite some time but without succes, so i turned to you guys :)
Thanks to all of you in Advance!
Sorry your description doesnt make much sense to me. I cant even see Employee,
Month etc fields in posted data.
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs
Similar Messages
-
Display multiple values in a column in ALV
I need to display plant order number from AFPO and PLAF table in reference to Goods Recepient(WEMPF) field.
now in final internal table I assign AFPO--> Plant number value to PLNUM column of ALV.
how do I add value to same column based on WEMPF common value for both table and append value to PLNUM column below value fetched from AFPO table.
code for getting value from PLAF table.
SELECT WEMPF PLNUM
FROM PLAF
INTO TABLE IST_PLAF
FOR ALL ENTRIES IN IST_AFPO
WHERE PLNNO = IST_AFPO-WEMPF
AND ......
Point is for some WEMPF field entried their will be number of entries in AFPO and PLAF table (in PLNUM column) so how I do displaying entries from both tables in single row??Hi Ankitkumar Dineshkumar Gautam,
SAP would say: "This is a consulting issue". I would say: What's your problem? Look at some samle programs.
Regards,
Clemens -
SSRS 2008 R2 - Add moving average to column group
I have a column group of dollar amounts. The row is a year/month. I would like to add a moving average column to the right of the last 6 months. My SQL Server data source is already complex enough and I'd really prefer not to add a column
there. Is there anything I can do within the report itself? Some way to reference the previous records in a matrix?
Thank you!Hi mateoc15,
According to your description, you have a matrix in your report. Now you want to calculate the average value of last 6 month. Right?
In Reporting Service, we can put custom code into report to deal with complicated logic. Add one more column/row inside of group and call the functions defined in custom code. For your requirement we modified Robert’s code to achieve your goal. We tested
your case in our local environment with sample data. Here are steps and screenshots for your reference:
Put the custom code into report:
Private queueLength As Integer = 6
Private queueSum As Double = 0
Private queueFull As Boolean = False
Private idChange As String=""
Dim queue As New System.Collections.Generic.Queue(Of Integer)
Public Function CumulativeQueue(ByVal currentValue As Integer,id As String) As Object
Dim removedValue As Double = 0
If idChange <> id then
ClearQueue()
idChange = id
queueSum = 0
queueFull = False
CumulativeQueue(currentValue,id)
Else
If queue.Count >= queueLength Then
removedValue = queue.Dequeue()
End If
queueSum += currentValue
queueSum -= removedValue
queue.Enqueue(currentValue)
If queue.Count < queueLength Then
Return Nothing
ElseIf queue.Count = queueLength And queueFull = False Then
queueFull = True
Return queueSum / queueLength
Else
Return (queueSum) / queueLength
End If
End If
End Function
public function ClearQueue()
Dim i as Integer
Dim n as Integer = Queue.Count-1
for i=n To 0 Step-1
queue.Dequeue()
next i
End function
Add one more row inside of group, call the function defined in custom code.
Save and preview. It looks like below:
Reference:
Moving or rolling average, how to?
If you have any question, please feel free to ask.
Best Regards,
Simon Hou (Pactera) -
How to update person or group column with peopleeditor control values
Hi,
I have created custom aspx page and added "PeopleEditor" control(can select multiple users) in that page. Now I am trying to update person or group column with peopleeditor control values.I am not getting any error if I select single user
in PeopleEditor control but getting error if I select more than one user.
UpdateItem(listItem, "ListColumnName",
listItem.ParentList.ParentWeb.EnsureUser(peopleeditorId.CommaSeparatedAccounts));
Can anybody help me out to resolve the issue?
Thank you in advance!!!
AA.First get all the users/groups from the PeapleEditor by using PeapleEditor.ResolvedEntities
foreach (PickerEntity pickerEntity in peopleEditor.ResolvedEntities)
SPPrincipalType principalType = (SPPrincipalType)Enum.Parse(typeof(SPPrincipalType), pickerEntity.EntityData["PrincipalType"].ToString());
if (principalType == SPPrincipalType.User || principalType == SPPrincipalType.SecurityGroup)
string loginName = pickerEntity.Key;
//your code here
else if (principalType == SPPrincipalType.SharePointGroup)
string groupName = pickerEntity.Key;
//your code here
Add all the users/groups in an instance of SPFieldUserValueCollection
and then update your list item.
SPFieldUserValueCollection users = new SPFieldUserValueCollection();
users.Add(new SPFieldUserValue(web,user.ID,user.Name));
item["YourUserColumn"] = users;
item.Update(); -
How to add only highest values in the column
Hello All,
We have report where I need to add only highest values in 'Price' column.
Ex:
Group Mat Price
Grp1 Mat1 50
Mat2 75
Mat3 100
Grp2 Mat1 50
Mat2 100
I need my result as 200...
Any input is appreciated!
Thanks in advance !!
Venu.Sriman/Surendra,
Unfortunately, this approach does not work because the Calculate Result As --> Maximum applies not only to the subtotals but also to the grand total. Therefore, the result in Venu's example will be:
MAX(Grp1) = 100
MAX(Grp2) = 100
MAX(All Grps) = 100
We have the same requirement as Venu, but have not found a satisfactory solution yet. The only way we have solved such problems in the past is to use VBA in workbooks, but the report we are using now is a Web report.
Hope this helps to clarify the issue...
Bob -
what is difference between distribution list and share point group? Can we add distribution list into person and group column of share point list?
there is a workaround you can try, create audience and add DL to them and deal with the audience or convert DL to groups
https://social.technet.microsoft.com/Forums/en-US/02f0d773-8188-4d94-a448-0c04d838b0cf/distribution-lists-in-sharepoint?forum=sharepointgenerallegacy
Kind Regards,
John Naguib
Technical Consultant/Architect
MCITP, MCPD, MCTS, MCT, TOGAF 9 Foundation
Please remember to mark your question as answered if this solves your problem -
How to add description of a column of a table in SQL Azure
Hi
I have some tables in my application database where there are descriptions added against certain columns. Needless to say they were done by using sp_addextendedproperty.
Now I am trying to migrate the Database to SQL Azure. SQL Azure does not support sp_addextendedproperty.
Hence I am not able to figure out how to add descriptions to those columns.
Any help would be much appreciated.
Thanks
SoumyadebHello,
Just as Latheesh post above, Windows Azure SQL database are not support extended stored procedures. That’s one of the limitations on SQL database, and I don’t know there is another way to achieve the same on Azure.
Regards,
Fanny Liu
Fanny Liu
TechNet Community Support -
Sql Loader INFILE name value in table column Value
Hi,
Here is my Sql Loader Script
LOAD DATA
infile '%1'
APPEND INTO TABLE XX_SUPPLIER_UPD
FIELDS TERMINATED BY ";" OPTIONALLY ENCLOSED BY '"' TRAILING NULLCOLS
ACTION Char
,ADDRESS_TYPE Char
,REGION Char "LTRIM(RTRIM(:REGION))"
,PO_BOX Char
,,WWW_ADDRESS Char
,status Char "NVL(:status,'X')"
,filename Char "replace(:infile,'\"','')"
I am getting the infile name as the parameter and i want to insert that parameter value in the column name fillename. Can any one guide me to how to do.
Cheers!
Jayaraj.SIf you were to use external tables instead of SQL*Loader, you can dynamically change the location of the external table (i.e. the filename) using a simple ALTER TABLE statement.
External tables also mean that all the control is inside the database rather than relying on external utilities and external scripts.
;) -
How to show the VALUE as the Column Header using SQL query?
Hi
I have a requirement to show the picked value as the column header using SQL query.
Example:
======
SELECT EMPNO FROM EMP
WHERE EMPNO=7934;
Result Should be:
7934
7934I have a requirement to show the picked value as the column header using SQL query.In sql*plus you can do
SQL> set verify on
SQL> def e = 7934
old: SELECT empno "&&e" FROM emp WHERE empno = &&e
new: SELECT empno "7934" FROM emp WHERE empno = 7934
SQL> SELECT empno "7934" FROM emp WHERE empno = 7934
7934
7934
1 row selected. -
Hi everyone,
Using the Writer block, configured with a correct SQLAzure instance, I experience this error:
- Error 1000: AFx Library library exception: Sql encountered an error: These columns don't currently have unique values.
I have read that this error can be related to inheritance problems, but my table does not have inheritances of any kind:
CREATE TABLE [dbo].[my_table](
[my_float] [float] NULL
) ON [PRIMARY]
GO
Writer block parameters:
Comma separated list of columns to be saved:
temp (from Bike Rental UCI Dataset)
Data Table name: [dbo].[my_table]
Comma separated list of datatable columns:
[my_float]
The experiment from which I have extracted the writing part was able to correctly write to DB until few days ago. Is it possible that some changes in the platform are causing this issue or am I doing something wrong?
Thank you and best regards,
FVHi Maureen,
Yes, the scenario is correct. On SQL profiler I can't see any SQL operation that can lead to that kind of error, but as you were saying it was worth trying anyway having that error message.
New test scenario:
CREATE TABLE [dbo].[my_table_identity](
[ID] [int] IDENTITY(1,1) NOT NULL,
[my_float] [float] NULL,
CONSTRAINT [PK_my_table_identity] PRIMARY KEY CLUSTERED
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
) ON [PRIMARY]
-- These lines work fine on SQL Management Studio
INSERT INTO [dbo].[my_table_identity] (my_float) VALUES (1.23)
INSERT INTO [dbo].[my_table_identity] (my_float) VALUES (1.23)
INSERT INTO [dbo].[my_table_identity] (my_float) VALUES (1.23)
-- I can see all new rows with each one a different ID
SELECT * FROM [dbo].[my_table_identity]
dbo is the default schema for my Azure login.
New writer block parameters:
Comma separated list of columns to be saved: temp
(from Bike Rental UCI Dataset)
Data Table name: my_table_identity
Comma separated list of datatable columns: my_float
I still get the same error: Error 1000: AFx Library library exception: Sql encountered an error: These columns don't currently have unique values.
I have also tried to pass the "instant" column instead of "temp", as it hasn't any duplicated values, but still no luck.
I attach the log file (purged of sensitive information) because I see some error / warnings there.
https://dl.dropboxusercontent.com/u/40411467/azure_log.txt
Thank you again and best regards,
FV -
Formula to populate one Person or Group column depending on the value of another Person Group column
I am looking for a way to popluate the Account information of a Person based on another column where there name in another column. I have Two Columns "Name" which is a Person or Group information type and User Account which
is also a Person or Group Information type. When an Invidividuals name is entered into the Name column, I what the User Account column to prepolulate.Hi,
For your issue, you can automatically populate User Information depending on the value of another Person or Group column by connectting with User Information List or connectting with User Profile Web Service:
http://www.wonderlaura.com/Lists/Posts/Post.aspx?ID=172
http://blogs.technet.com/b/anneste/archive/2011/11/02/how-to-create-an-infopath-form-to-auto-populate-data-in-sharepoint-2010.aspx
Best Regards,
Eric
TechNet Community Support
Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
[email protected] -
How to have a common value for a column using sql loader
Hi Have a sql loader file which looks like below. But I am not getting how insert the same value for the column in all rows.
id,
crt_user_id
BEGINDATA
1;"system"
2;"system"
3;"system"
So, instead of entering the crt_user_id as system in all rows, can we place the value at the top after the column name?Thanks Srini. your hint/suggestion helped me in finding the solution.
LOAD DATA
INFILE *
BADFILE './TEST.BAD'
DISCARDFILE './TEST.DSC'
APPEND INTO TABLE TEST_TABLE
Fields terminated by ";" Optionally enclosed by '"'
ID,
crt_user_id CONSTANT 'SOME CONSTANT VALUE'
BEGINDATA
1
2
3
so by using CONSTANT key word, we can avoid tying the same value in the data -
User or group column is populated with incorrect values when adding data from CSOM
Hi All,
I am working on a console application that updates list items using managed CSOM. I have a user or group column in this list that can contain multiple values. Now, I am using below code to update the value of this column:
User newUser = web.EnsureUser("LoginName");
context.Load(newUser);
context.ExecuteQuery();
FieldUserValue userValue = new FieldUserValue();
userValue.LookupId = newUser.Id;
listItem["User"] = userValue;
The issue is if i assign the value of user1 to this column, the value that I see after the column is updated is another user; like user2. I don't know why it is populating this code with some other user?
Any idea on this issue? Thanks in advance.try these links:
http://blogs.msdn.com/b/kaevans/archive/2013/11/30/setting-a-sharepoint-person-or-group-field-value-with-csom.aspx
http://stackoverflow.com/questions/637859/sharepoint-group-by-is-broken-when-using-allow-multiple-values-for-a-column
http://stackoverflow.com/questions/26815640/caml-person-or-group-field-with-multiple-values
Please mark answer as correct if it is correct else vote for it if you find it useful -
SSRS Compare a string value in an column
I need to show a text box that shows a message if the string values of a column on SSRS report have mixed values.
I need to compare the first three letters of a string to see if its different. If different then unhid Textbox and show a message. How can I do this in SSRS or SQL (if sql how do I feed it to SSRS)?
For example
Substring(alloy,1,3) <> Substring(alloy,1,3)
ALLOY
KZA1
KZD1 << is different
KZA2If your scope is the whole dataset then you can add a total row to the tablix outside any groups or
simply add a textbox below the tablix and apply the same principle:
=IIf(Min(Fields!Alloy.Value,"DatasetName") <> Max(Fields!Alloy.Value,"DatasetName"), "Mixed Alloy", "")
=IIf(Min(Left(Fields!Alloy.Value,3),"DatasetName") <> Max(Left(Fields!Alloy.Value,3),"DatasetName"), "Mixed Alloy", "")
This should do what you are asking. The only way that the minimum value for alloy will equal the maximum value for allow is if all values for alloy in the dataset are the same. When that happens, empty string is displayed in your text box rendering it invisible
if you set borders appropriately. Otherwise you will see "Mixed Alloy" in the text box.
"You will find a fortune, though it will not be the one you seek." -
Blind Seer, O Brother Where Art Thou
Please Mark posts as answers or helpful so that others may find the fortune they seek. -
How to use Default value in a column in Tabular form in insertion or upda
Hello,
I am trying to use Default values so that user need not have to enter data, but when I select default type and put a default value, I see an error message, if I try to add a new row.
How can I use a default value in a Column in a Tabular Form?
Gouri
Edited by: user1046395 on Apr 3, 2009 9:58 AMGouri,
You can just simply edit to each column's report attribute. For example,
To set default date,
Default Type: PL/SQL Expression of Function
Default: sysdate
To set default text,
Default Type: PL/SQL Expression of Function
Default: *'CLERK'*
If you still have an error, what is the error message?
Ittichai
Maybe you are looking for
-
Here's the sequence of events: Setting up a new iMac. Migration Assistant was aborted during setup and a normal setup was completed. Then ran Migration Assistant from the newly setup account. It ran fine, but put all the data in a new account called
-
Sort Array of References by Label-Name
I am developing on an DSC application with shared variables and alarming and events with a hugh amount of variables. Each variable is displayed on the front panel within tab controls. To reduce time and effort when expanding the variables I would lik
-
When I downloaded iWork on my MacBook Air, it didn't copy the application to my other devices. Is that an error or should I buy them again on each device!?
-
How to use Toolkit.getDefaultToolkit().getImage in JPanel in Java Swing
Hi Sir, I want to know how to use Toolkit.getDefaultToolkit.getImage() in JPanel (ie) the class that extends the JPanel.There is no problem to include the Toolkit.getDefaultToolkit.getImage()in JFrame.It is displaying it without any problem.But in JP
-
0report_template_export Transporting
Hi all, I have developed a report in 'Report Designer' and this report has to Brodecast everyday. For this I have taken a copy of standard Template and crated own template to designe this report in Report Designer. I have moved below objects for BI D