I'm having a table in Collection1 and it is having 8 columns in it. Now I want to merge Column1, Column3, Column5 and Column7. Is there any solution for those columns using blueprism
You simply need to copy the collection with a new column, then loop through each row to create the merged values...
Something like that:
Add Column Field9 contains the standard object Utility - Collection Manipulation, with page 'Append Field (Text)', as inputs I have [Coll1] for the input collection, "Field9" for the new Field Name and "" for the Value, as output I have Coll2.
The loop is on Coll2
Merge Columns is simply [Coll2.Field1]&[Coll2.Field3]&[Coll2.Field5]&[Coll2.Field7] with result being stored in Coll2.Field9.
Coll1 contains 8 columns, each column named Field1 through Field8. Coll2 is the new collection, it is empty before the merge.
You can choose to delete the columns you don't need afterwards, with the page 'Delete Field' from the same object (Utility - Collection Manipulation).
Related
I have a database A.db, which contains tables t1, t2 and t3.
Now I want to create a new database B.db, which contains t1 and some chosen columns col1 and col4 from t2.
With .import I get hundreds of errors and it seems to work only for full tables.
.output sounds like I just save the output as it would be printed.
Basically, I need an insert into foo select ... across different files. How can I do this?
First you must attach A.db to your current database and give it an alias like adb.
Then write the insert statement just like you would if all the tables existed in the same database, qualifying the column names with the database alias.
It's a good practice to include in the insert into... statement inside parentheses all the column names of the table foo for which you will set values from the other 2 tables, but also be sure that the order of the columns is the same with the order of the columns in the select list:
attach database 'pathtoAdatabase/A.db' as adb;
insert into foo (column1, column2, .......)
select adb.t1.column1, adb.t1.column2, ...., adb.t2.col1, adb.t2.col4
from adb.t1 inner join adb.t2
on <join condition>
Replace <join condition> with the conditions on whichyou will join the 2 tables to makes the rows that you will insert into foo, something like:
adb.t1.id = adb.t2.id
Sorry in advance due to being new to Rstudio...
There are two parts to this question:
1) I have a large database that has almost 6,000 tables in it. Many of these tables have no data in them. Is there a code using R to only pull a list of tables names that have data in them?
I know how to pull a list of all table names and how to pull specific table data using the code below..
test<-odbcDriverConnect('driver={SQL Server};server=(SERVER);database=(DB_Name);trusted_connection=true')
rest<-sqlQuery(test,'select*from information_schema.tables')
Table1<-sqlFetch(test, "PROPERTY")
Above is the code I use to access the database and tables.
"test" is the connection
"rest" shows the list of 5,803 tables names.. one of which is called "PROPERTY"
"Table1" is simply pulling one of the tables named "PROPERTY".
I am looking to make "rest" only show the data tables that have data in them.
2) My ultimate goal, which leads to the second question, is to create a table that shows a list of every table from this database in column#1 and then column 2,3,4,etc... would include every one of the column headers that is contained in each table. Any idea how do to that?
Thanks so much!
The Tables object below returns a data frame giving all of the tables in the database and how many rows are in each table. As a condition, it requires that any table selected have at least one record. This is probably the fastest way to get your list of non-empty tables. I pulled the query to get that information from https://stackoverflow.com/a/14163881/1017276
My only reservation about that query is that it doesn't give the schema name, and it is possible to have tables with the same name in different schemas. So this is likely only going to work well within one schema at a time.
library(RODBCext)
Tables <-
sqlExecute(
channel = test,
query = "SELECT T.name TableName, I.rows Records
FROM sysobjects t, sysindexes i
WHERE T.xtype = ? AND I.id = T.id AND I.indid IN (0,1) AND I.rows > 0
ORDER BY TableName;",
data = list(xtype = "U"),
fetch = TRUE,
stringsAsFactors = FALSE
)
This next part uses the tables you found above and then gets the column information from each of those tables. Lastly, it makes on single data frame with all of the column names.
Columns <-
lapply(Tables$TableName,
function(x) sqlColumns(test, x))
Columns <- do.call("rbind", Columns)
sqlColumns is a function in RODBC.
sqlExecute is a function in RODBCext that allows for parameterized queries. I tend to use that anytime I need to use quoted strings in a query.
I am attempting to add a dynamic column to a table in spotfire that is updated using r-script/data functions in order to handle different variable types. When you just insert columns, it does not allow you to change the column from a text value to a string value.
The basic code structure is create a new table by merging the base table with the information table, select a column header to populate the new column from, and return the calculated column values to the base table. Parameters are as follows:
Input Parameters:
Name Type
columnMatch Value
baseTable Table
infoTable Table
Output Parameters (to be added to baseTable)
Name Type
outputColumn Column
Script
newTable <- merge(baseTable,infoTable, by = "uniqueIdentifier")
cnames <- colnames(newTable)
outputColumn <- newTable[,match(colorSelection, cnames, nomatch=1)]
outputColumn
The issue thatI am having is as follows:
The code is not returning the correct value for the correct uniqueIdentifier. Is there a way that I can make the values line up, or sort the table in order to return the correct value for the correct uniqueIdentifier?
Thanks!
Jordan
EDIT: found out how to dynamically refer to column number using match function.
I added a new column to my table, so there are now 4 instead of 3, and am now getting the following error when do a parametric insert (looped):
table 'test' has 4 columns but 3 values were supplied
Does this mean that you have to code your query for EVERY column the table has (as opposed to just the columns you want populated) when doing inserts, and that SQLite won't just add a default value if a column is missing from the query?
My query is:
"INSERT OR IGNORE INTO test VALUES (NULL, #col2, #col3)"
And this is the code that controls what's inserted in the recursive lopp:
sqlStatement.clearParameters();
var _currentRow:Object = _dataArray.shift();
sqlStatement.parameters["#col2"] = _currentRow.val2;
sqlStatement.parameters["#col3"] = _currentRow.val3;
sqlStatement.execute();
Ideally, I'd like column 4 to be left blank, without having to code it into the query.
Thanks for taking a look.
If you're inserting less values than there are columns, you need to explicitly specify the columns you are inserting to. For example
INSERT INTO test(firstcolumn,secondcolumn) VALUES(1,2);
Those columns that are not specified will get the default value, or NULL if there is no default value.
In web application, I fetch the data from back end and the data is now availbale in dataset. I have 5 columns in that dataset, but i need only one column, so how can i get only one column out of 5 columns. I use dataview but it is not getting.
DataView dv = ds.Tables[0].DefaultView;
dv.RowFilter= "empid";
but i am not getting. can you helpme
With the help of dataview you can create another table which has only required columns which you need
DataView view = new DataView(ds.tables[0]);
DataTable newTable = view.ToTable(tabblename, false, params string[] columnNames
);//Add name of required
You can get full example from the below link
Click
or
You can remove extra columns
ds.Tables[string].Columns.Remove(string)
to remove individual columns which you feel are extra one.
Don't forget to ds.AcceptChanges() after deleting rows or they will still be in the dataset.
You can set the dv.AutoGenerateMembers to false then create on column inside yourDataView (using designer approach) that matches the names of that column you want to show on the DataView