Using parameter values to parse XML when using CROSS APPLY - xml-parsing

I have the following SQL to parse an XML data type stored in a table within SQL Server:
SELECT
N.C.value('CustomerID[1]', 'int') value
FROM dbo.t_xml_input
CROSS APPLY xmlcol.nodes('/Root/Customers') N(C);
I want to parameterise the node, value and definition variables so that I can use the same SQL within a cursor to extract different data items from the XML i.e. something like:
SELECT
N.C.value('#para1', '#para2') value
FROM dbo.t_xml_input
CROSS APPLY xmlcol.nodes('#para3') N(C);
The #para values will be stored in a table, which I will retrieve and loop through.
Is this at all possible and if so what is the correct syntax?
Thanks.

Related

Write to BQ one field of the rows of a PColl - Need the entire row for table selection

I have a problem:
My Pcoll is made of rows with this format
{'word':'string','table':'string'}
I want to write into BigQuery only the words, however I need the table field to be able to select the right table in BigQuery.
This is how my pipeline looks:
tobq = (input
| 'write names to BigQuery '>> beam.io.gcp.bigquery.WriteToBigQuery(
table=compute_table_name, schema=compute_schema,
insert_retry_strategy='RETRY_ON_TRANSIENT_ERROR',
create_disposition=beam.io.gcp.bigquery.BigQueryDisposition.CREATE_IF_NEEDED,
write_disposition=beam.io.gcp.bigquery.BigQueryDisposition.WRITE_APPEND)
)
The function compute_table_name accesses an element and returns the table field. Is there a way to write into BQ just the words while still having this table selection mechanism based on rows?
Many thanks!
Normally the best approach with a situation like this in BigQuery is to use the ignoreUnknownValues parameter in ExternalDataConfiguration. Unfortunately Apache Beam doesn't yet support enabling this parameter while writing to BigQuery, so we must find a workaround, as follows:
Pass a Mapping of IDs to Tables as a table_side_input
This solution only works if identical word values are guaranteed to map to the same table each time, or there is some kind of unique identifier for your elements. This method is a bit more involved than Solution 1, but it relies only on the Beam model instead of having to touch the BigQuery API.
The solution involves making use of table_side_input to dynamically pick which table to place an element even if the element is missing the table field. The basic idea is to create a dict of ID:table (where ID is either the unique ID, or just the word field). Creating this dict can be done with CombineGlobally by combining all elements into a single dict.
Meanwhile, you use a transform to drop the table field from your elements before the WriteToBigQuery transform. Then you pass the dict into the table_side_input parameter of WriteToBigQuery, and write a callable table parameter that checks with the dict to figure out which table to use, instead of the table field.

How to SELECT, modify and INSERT data in Influx DB?

I'm new to InfluxDB. I currently have two databases in influx. I now want to copy certain data points from a measurement in the database1, then I want to introduce a couple field sets manually and modify the few field values that I copied and finally insert the changed data points in database2 under a different measurement.
I can use the select into statement however that will not allow me to make changes to the datapoint.
If I use the Insert command I will have to type all the field sets and tag sets individually.
I have a solution that I can use python and query the data points and manipulate the data then insert it back. However that will be a lengthy process.
Is there any easy way to accomplish this task?
Thanks.

SSRS: Passing different parameter values to stored procedure for two Data Sets

I have two tables in my Report. Both use two separate Data Sets, which get data from the same Stored Procedure. Now, I want the data sets to get different data based on different parameter values. Is there a way to achieve that? I am using SQL Server 2008-R2. Thanks in advance...
Within the Report Data screen (Ctrl+Alt+D), you can tie both datasets up to different parameters.
Add your parameters
Open up the Datasets properties
Go to the parameters section
Add the required parameter and give it a name the same as your Stored Proc parameter e.g. #EmployeeId
providing the query is marked as type "Stored Procedure" (in query section), this will pass the parameter over on selection. Repeat the process for the other dataset

multi value return SP

How can you return multi values from one Stored procedure.
You can do this in the following way (These relate to SQL Server, the syntax may be different with other databases.)
Use multiple OUTPUT parameters
See: http://msdn.microsoft.com/en-us/library/ms378108.aspx
Have multiple select statements in a stored procedure.
Use return value's
See: http://sqlserverpedia.com/wiki/Stored_Procedures_-_Output_Parameters_%26_Return_Values

Informix - Aggregating list of values into comma-delimited string

Is there a way to convert a list of values into a comma-delimited string in Informix? For example, I have the following query as a subselect:
SELECT [State] From States
I would like to convert all the values from that select into a comma-separated list.
Can I do that in informix?
I think the answer you need is given in these questions: SO 715350, SO 489081. It shows how to create and use a GROUP_CONCAT() aggregate that will do exactly what you want. The functionality is otherwise not available - that is, you have to add it to Informix, but it can (fairly) easily be added.

Resources