Microsoft word Database quick part - How to use a mergefield as a filter for the database query - database

I am using mail merge to input data from an excel sheet. Everthing works great and I can access my variables using «MyMergefield»
Now I need for each letter generated to look into another excel file and do a query that will take the «MyMergefield» as a query filter SELECT FROM x WHERE field1 = «MyMergefield»
The way I am proceeding is "inserting a quick part" => "Field" in my word document.
In the quickpart dialog, I choose "DataBase", then I choose my excel file.
once the data source is chosen, There an option to change the request parameters, I click on it and I get the filter configuration popup where I can choose the field (from the excel sheet), the operator ("equals" in this case). Then there's the compare with field. In my case its not as simple as comparing to as string. Its comparing to a mail merge field.
I tried the following syntax:
«Myfield»
MERGEFIELD Myfield
MERGEFIELD "Myfield"
{MergeField Myfield}
{ MERGEFIELD Myfield}
None worked, it complained that it did not find any match so it did not insert the database (Of course it will not find any match to the syntax if I don't run mail merge)
I did look directly in the openxml file of an existing example (because I can't edit existing quickpart - Correct me if Im wrong) and the database query looked like:
FROM `Candidates$` WHERE ((`column` = '</w:instrText>
...
<w:instrText xml:space="preserve"> MERGEFIELD Myfield</w:instrText>
</w:r>
Any ideas? Thank you!

Related

How pull a select html formatted chunk of a google spreadsheet using a URL

I have a tree farm.
I have a Google spreadsheet that has my inventory in the form that I took it.
I have pivot table that summarizes that sheet.
How can I run a query from the Jack Pine description page on my website that pulls the appropriate blob off the pivot table on the spreadsheet?
Here's what I've done so far:
Create a new spreadsheet that does an importrange() from the individual sheet with my pivot table.
Share to the world, published to the web. Using another browser where I am not logged in with my google ID I can see the file, and it is view only.
https://docs.google.com/spreadsheets/d/13pXb7Kek010B6s8Ez3h6yX4qF92MgvV4uMk71dJhe3o/edit#gid=0
I'm basing this on this article: [https://blog.ouseful.info/2009/05/18/using-google-spreadsheets-as-a-databace-with-the-google-visualisation-api-query-language/][1]
Now, in a query (split line for reading convenience)
https://spreadsheets.google.com/d/
13pXb7Kek010B6s8Ez3h6yX4qF92MgvV4uMk71dJhe3o/tq?
tqx=out.html&tq=select+*+where+B+contains+%27Pine,%20Jack%27
And I get the following message:
google.visualization.Query.setResponse({
"version":"0.6","status":"error","errors
[{"reason":"access_denied","message":"Access
denied","detailed_message":"Access denied"}]});
Obviously I'm missing something here. How do I troubleshoot this?
Google has changed something. This answer no longer works
Added Sunday.
The following now will fetch the entire sheet:
https://docs.google.com/spreadsheets/d/
13pXb7Kek010B6s8Ez3h6yX4qF92MgvV4uMk71dJhe3o/
edit?tqx=out.html&tq=select+A,B,C,+where+A+starts+with+%27Pine%27#gid=0
But while it fetches, the select statement returns the entire sheet, or rather the query is ignored.
(I originally had %20's for all the +'s, but Google rewrote them, or my browser does.)
This method
https://docs.google.com/spreadsheets/d/
13pXb7Kek010B6s8Ez3h6yX4qF92MgvV4uMk71dJhe3o/
gviz/tq?tq=select%20A,B,C%20where%20A%20contains%20'Pine'#gid=0
returns a file json.txt. I don't read JSON, but sliding over the brackets and punctuation the content is there.
Note the difference around gviz/tq...
Google rewrites the URL removing tq? from it.
I cannot leave the tqx=out.html in place. I get no JSON file and a 'file unavailable error.'
Turns out what I need is tqx=out:html Colon, not period.
Found the information in a table labeled "Request Format" in the document
https://developers.google.com/chart/interactive/docs/dev/implementing_data_source

How to reference sub-objects in talend schema

So I have the following SOQL query that includes the ActivityHistories relationship of the Account object:
SELECT Id, Name, ParentId, (SELECT Description FROM ActivityHistories)
FROM Account
WHERE Name = '<some client>'
This query works just in in SOQLXplorer and returns 5 nested rows under the ActivityHistories key. In Talend, I am following the instructions from this page to access the sub-objects (although the example uses the query "up" syntax, not the query "down" syntax. My schema mapping is as follows:
The query returns the parent Account rows but not the ActivityHistory rows that are in the subquery:
Starting job GetActivities at 15:43 22/06/2016.
[statistics] connecting to socket on port XXXX
[statistics] connected
0X16000X00fQd61AAC|REI||
[statistics] disconnected
Job GetActivities ended at 15:43 22/06/2016. [exit code=0]
Is it possible to reference the subrows using Talend? If so, what is the syntax for the schema to do so? If not, how can I unpack this data in some ay to get to the Description fields for each Account? Any help is much appreciated.
Update: I have written a small python script to extract the ActivityHistory records and dump them in a file, then used a tFileInput to ingest the CSV and then continue through my process. But this seems very kludgey. Any better options out there?
I've done some debugging from the code perspective and it seems that if you specify correct column name, you will achieve the correct response. For your example, it should be: Account_ActivityHistories_records_Description
The output from tLogRow will be similar to:
00124000009gSHvAAM|Account1|tests;Lalalala
As you can see, the Description from all child elements are stored as 1 string, delimited by the semicolon. You can change the delimiter on Advanced Settings view on the SalesforceInput.
I have written a small python script (source gist here) to extract the ActivityHistory records and dump them in a file (command line argument), then used a tFileInput to ingest the CSV and then continue through my process.

How to create a RethinkDB data initialization script

I'm trying to create a simple script that I can paste into the RethinkDB data explorer to initialize a database.
I can insert records fine with something like this:
r.db('testdb').table('cars').insert([{ "model" : Honda }])
But how can that be followed by a second insert into a related table like:
r.db('testdb').table('engines').insert([{ "cars_id" : <what goes here> }])
I could imagine writing some javascript to extract the newly created id's, but it doesn't appear that the data explorer supports things like variables.
Ideally there would be a way to write a large script that would work directly in data explorer for when needed for convenience.
The data explorer can take multiple queries separated by a semi colon.
Note that queries will be sequentially executed, and only the result for the last query will be returned.
The data explorer supports some javascript to some extent, the requirements (as far as I know) are:
the last query must be a ReQL query
Any instructions must ends with a semi colon (except the last one)
That being said, you cannot use the result of the first query in the second query using JavaScript (you don't get access to the result). You can however nest queries (or chain with do), something like this should work I think:
r.db('testdb').table('cars').insert([{ "model" : Honda }]).do(function(result) {
r.db('testdb').table('engines').insert([{ "cars_id" : <you can use the result of the insert here> }])
})

How to retrieve the name of a file and store it in the database using SSIS package?

I'm doing an Excel loop through fifty or more Excel files. The loop goes through each Excel file, grabs all the data and inputs it into the database without error. This is the typical process of setting delay validation to true, and making sure that the expression for the Excel Connection is a string variable called EFile that is set to nothing (in the loop).
What is not working: trying to input the name of the Excel file into the database.
What's been tried (edit; SO changed my 2 to 1 - don't know why):
Add a derived column between the Excel file and database input, and add a column using the EFile expression (so under Expression in the Derived Column it would be #[User::EFile]). and add the empty. However, this inputs nothing a blank (nothing).
One suggestion was to add ANOTHER string variable and set its properties EvaluateAsExpression to True and set the Expression to the EFile variable (#[User::EFile]). The funny thing is that this does the same thing - inputs a blank into the database.
Numerous people on blogs claim they can do this, yet I haven't seen one actually address this (I have a blog and I will definitely be showing people how to do this when I get an answer because, so far, these others have fallen short). How do I grab an Excel file's name and input it in a database during a loop?
Added: Forgot to add, no scripts; the claim is that it can be done without them, so I want to see the solution without them.
Note: I already have the ability to import the data from the Excel files - that's easy (see my GitHub account, as I have two different projects for importing all sorts of txt, csv, xls, xlsx data). I am trying to also get the actual name of the file being imported also into the database. So, if there are fifty Excel files, along with the data in each file, the database will have the fifty file names alongside that data (so if each file has 1000 rows of data, each 1000 rows would also have the name of the file they came from next to them as an additional column). This point seems to cause a lot of confusion, as people assume I'm having trouble importing data in files - NOPE, see my GitHub; again that's easy. It's the FILENAME that needs to also be imported.
Test package: https://github.com/tmmtsmith/SSISLoopWithFileName
Solution: #jaimet pointed out that the Derived Column needed to be the #[User::CurrentFile] (see the test package). When I first ran the package, I still got a blank value in my database. But when we originally set up the connection, we do point it to an actual file (I call this "fooling the package"), then change the expression on the connecting later to the #[User::CurrentFile], which is blank. The Derived Column, using the variable #[User::CurrentFile], showed a string of 0. So, I removed the Derived Column, put the full file path and name in the variable, then added the variable to the Derived Column (which made it think the string was 91 characters long), then went back and set the variable to nothing (English teacher would hate the THENs about right now). When I ran the package, it inputted the full file path. Maybe, like the connection, it needs to initially think that a file exists in order for it to input the full amount of characters?
Appreciate all the help.
The issue is because of blank value in the variable #[User::FileNameInput] and this caused the SSIS package to assume that the value of this variable will always be of zero length in the Derived Column transformation.
Change the expression on the Derived column transformation from #[User::FileNameInput] to (DT_STR, 2000, 1252)#[User::FileNameInput].
Type casting the derived column to 2000 sets the column length to that maximum value. The value 1252 represents the code page. I assumed that you are using ANSI code page. I took the value 2000 from your table definition because the FilePath column had variable VARCHAR(2000). If the column data type had been NVARCHAR(2000), then the expression would be (DT_WSTR, 2000)#[User::FileNameInput]
Tim,
You're using the wrong variable in your Derived Column component. You are storing the filename in #[User::CurrentFile] but the variable that you're using in your Derived Column component is #[User::FileNameInput]
Change your Derived Column component to use #[User::CurrentFile] and you'll be good.
Hope that helps.
JT
If you are using a ForEach loop to process the files in a folder then I have have used the technique described in SSIS Junkie's blog to get the filename in to an SSIS variable: SSIS: Enumerating files in a Foreach loop
You can use the variable later in your flow to write it to the database.
TO all intents and purposes your method #1 should work. That's exactly how I would attempt to do it. I am baffled as to why it is not working. Could you perhaps share your package?
Tony, thanks very much for the link. Much appreciated.
Regards
Jamie

SQL Server "Optional" FreeText Search

I'm writing a search query in SQL Server 2005 for a discussion board. The proc takes several parameters, but most are "optional". There's one search field for Message Body, which I have a full text index on. Here's the problem..
If I pass in a value to search against with FreeText, the search works fine (thank you Microsoft). However, the message body field is optional, meaning that in my query, I want to handle a "search all". How can I default my query to just use any\all records regardless of the data held in my message body field?
I know this doesn't work, but if no value is returned for the message body parameter, Im looking for something like:
where (FREETEXT(msg.messagebody, '*'))
You could do something like:
select * from Products_CatalogProducts where (#keywords='*' or freetext(msg.messagebody,#keywords))
Assuming you passed in #keywords with a * if it's blank

Resources