Turning rows from sql table into headers in Pentaho - pentaho

I have a SQL table that return name and I would like to take that result and turn into headers (csv file)
for example: select name from TBL give me
name
Client Name
Phone Number
City
Is it possible to turn those return rows and convert into a header? I have try to find something but had no luck. The reason for this is to make the header dynamic.

Related

T-SQL: Exclude Columns from a SELECT statement based on string

My overall goal is to create new tables by selecting columns in existing tables with certain patterns/tags in their column names. This is in SQL Server.
For example, I have a common need to get all contact information out of a company table, and into its own contact table.
I haven't been able to find a programmatic approach in SQL to express excluding columns from a SELECT statement based on string.
When looking to options like the COL_NAME function, those require an ID arg, which kills that option for me.
Wishing there was something built in that could work like the following:
SELECT *
FROM TABLE
WHERE COL_NAME() LIKE 'FLAG%'
Any ideas? Open to anything! Thanks!!
One trick could be to firstly using the following code to get the column names you desire:
select * from information_schema.columns
where table_name='tbl' and column_name like 'FLAG%'
Then concatenate them into a comma-delimited string and finally create a dynamic sql query using the created string as the column names.

Find out if a value exists in a column with a large input values set

What is the most effective (and simple) way to find out if a specific column cells of a table contain one of a given values?
To give you some background, I have a list of 1000 ID numbers. They might or might not exist in a "FileName" column of a table "ProcessedFiles" as a part of the filename.
Basically, I need to check which of these 1000 tasks have been processed (i.e. they exist in the table).
The thing that I came with seems very uneffective:
SELECT * FROM ProcessedFiles
WHERE FileName LIKE '%54332423%'
OR FileName LIKE '%234432%'
OR FileName LIKE '%342342%'
...
etc
Thanks for help!
You could create a temporary table and insert all the Ids in a column. Then you could cross join with the ProcessedFiles table and check for the id in the name with a like:
SELECT pf.*
FROM ProcessedFiles pf,table t
WHERE pf.FileName like '%'+t.Id+'%'
I tested the above and it worked on SQL Server.

Google Fusion queries: using wildcard for LOCATION parameter

I am querying a Google Fusion table as follows:
SELECT * FROM {mytableIDhere} WHERE col1 LIKE '%{mystringhere}%'
This shows all row data for entries containing {mystringhere} in column 1. Is it possible to use a * wildcard on the column field, so that the search applies to ANY column? I tried that, but I get a parse error when doing:
SELECT * FROM {mytableIDhere} WHERE * LIKE '%{mystringhere}%'
It seems that the location parameter cannot be open-ended. Is this correct? If so, is there a workaround?
EDIT: In terms of desired functionality, I am trying to create a global search of a table so that any rows containing the search query will be returned. The columns include e-mail addresses, ID numbers, commentary, and other values.

SQL Query: Modify records based on a secondary table

I have two tables in a PostgreSQL database.
The first table contains an ID and a text field with up to 200 characters and the second table contains a data definition table which has a column that contains smileys or acronyms and a second column which converts them to plain readable English.
The number of records in table 1 is about 1200 and the number in table two is about 300.
I wish to write a SQL statement which will convert any text speak in column 1 in table one into normal readable language based on the definitions in Table 2.
So for example if the value in table 1 reads as: Finally Finished :)
The transformed SQL would be something like: Finally Finished Smiles or smiling,
where the definition is pulled from the second table.
Note the smiley could be anywhere in the text in column one and could one of three hundred characters.
Does anyone know if this is possible?
Yes. Do you want to do it entirely in SQL, or are you writing a brief bit of code to do this? I'm not entirely sure of how to do it all in SQL but I would consider something like what is below:
SELECT row.textToTranslate FROM Table_1
oldText = row.textToTranslate
Split row.textToTranslate by some delimeter
For each word in row.textToTranslate:
queryResult = SELECT FROM Table_2 WHERE pretranslate=word
if(queryResult!=Null)
modifiedText = textToTranslate.replace(word, queryResult)
UPDATE Table_1 SET translatedText=modifiedText WHERE textToTranslate=oldText

How to find a text from database column in a table?

I have a database in SQL Server in which there is a table with a single column URL that contains URL.
I have 1000 rows (supposed).
Now I need to find that which URL contains the text that I will tell.
Example :
Sr. URL
1 http://example.com
2 http://example2.com
If I have these kind of data and I need to find that which row contains example2 or simply 2 then I should give me the specific row(s).
select id from table where URL like ('%example%');