Add a field description to a DB2/400 file - sql

I have a set of files in a library on an AS/400/iSeries/System-I/whatever-IBM-wants-me-to-call-it-these-days which I do not have DDS for (created in SQL I gather) but to which I would like to add field descriptions. I cannot find a way to do this on the 400.
Does anyone know how I can add field description? Is directly updating SYSIBM.SQLCOLUMNS to set COLUMN_TEXT safe?
(I am not looking for general SQL answers here, only DB2/400 specific answers. Unfortunately given IBMs renamings of this platform and the very un-google-able name they chose, it is almost impossible to find answers (or especially to prove that there is NOT an answer) to such questions without spending ages looking through there voluminous, impenetrable documentation)

Use the LABEL SQL command. If you are using the green-screen STRSQL command, you can prompt it. The LABEL command can be used to set both column text and column headings.
Here is an example of using the LABEL command to give column text for two fields in the file named TESTFILE1. The fields are named FIELD1 and FIELD2 in this example:
LABEL ON COLUMN TESTFILE1
(FIELD1 TEXT IS 'My Field 1 text', FIELD2 TEXT IS 'My Field 2 text')
Here is an example of using the LABEL command to give column headings that would show up in query results:
LABEL ON COLUMN TESTFILE1
(FIELD1 IS 'My field Heading 1',
FIELD2 IS 'My field Heading 2')
When creating column headings, you get 60 characters per field. The first 20 characters are line 1. The second 20 characters are line 2. The third 20 characters are line 3. In the above example, the field headings would look like this:
My field My field
Heading 1 Heading 2

As an additional hint, you can use iSeries Navigator to get the SQL statement for that file. If you fire up this program, log on to the iSeries, go to database, go to schemas, and go to tables, then you can find your file. You'll find the button "generate SQL" somewhere. This creates an exact SQL statement for you to create the table. You can use this SQL statement to work with this table.
For your questions, the "LABEL" from another answer is sufficient. This answer is usefull if you want to do more stuff, that can not be done with ALTER.

Related

Is there a way to reduce gap between two column headings in DB2

I am working on IBM I series VR7, and running SQL(DB2) using CLLE.
I have a SQL procedure in a TXT file, having below command to create a table in QTEMP.
create table qtemp.FILE1 as (
select
Field1,Field2,Field3,.....Field10 from FILE2 ) with data;
I am calling the above procedure from CLLE using below command.
RUNSQLSTM SRCFILE(MyLib/MySrc) SRCMBR(Proc_txt) COMMIT(*NONE)
And then running below command to generate the spool.
RUNQRY QRYFILE((FILE1)) OUTTYPE(*PRINTER) OUTFORM(*DETAIL) FORMSIZE(60 132)
FORMTYPE(*STD) COPIES(1) LINESPACE(1)
The issue I am facing is that I am getting 2 white spaces between columns while creating the table using the create table command. When that table is converted into a spool file using above RUNQRY command, the fields on the right side truncates as my report width is 132 by default and I can not change it.
If the white spaces in the table created can be reduced to 1, my issue will be resolved.
The SQL I am using IBM i Series' default and DB2 as database. I don't have much idea about their version.
Edit2: Another issue I had was of report having a field in second line. Actually as per requirement a field had to be in the second row under another field. For example I needed field10 under field5. I have fixed it too, read my answer below.
Hope it helps people in need but I really doubt.
Edit1: I have updated the question as requested. Any help would be much appreciated. Thanks.
The short answer is that yes you can define the report to have 1 space between columns, but you have to define the Query400 object to do that. Unfortunately this is not a good place to write a tutorial for Query400. I can get you started though.
Type wrkqry, press enter.
Then put the cursor on the query name field, and press F4. You are now in the tool. You need to create a new query, and define everything about it in this tool. Play around with it, and see if that helps you.
I was able to get what I needed. As others have suggested, I have finally used WRKQRY to control the column spacing. Reduced the column spacing to 1 and was able to get the columns needed in the 132 width.
Another issue I had was of report having a field in second line. Actually as per requirement a field had to be in the second row under another field. For example I needed field10 under field5. So what I did was, I used the Line wrapping feature available in WRKQRY.
How I did:
Create a WRKQRY object and select the file needed.
Sequenced the field I needed in second line, to the bottom.
Go to Select Output Type and Output Form and take Y on Line Wrapping field. Put the
wrapping width equal to your report width. Leave other fields as required.
This way each record will have 10th field in next row, if it has data. You can add as
many as fields.
You may have to add some white spaces to the field for proper alignment. I would
suggest to create a new field and use concat(||) operator available in WRKQRY.
Thanks everyone for helping.

PDI /Kettle - Passing data from previous hop to database query

I'm new to PDI and Kettle, and what I thought was a simple experiment to teach myself some basics has turned into a lot of frustration.
I want to check a database to see if a particular record exists (i.e. vendor). I would like to get the name of the vendor from reading a flat file (.CSV).
My first hurdle selecting only the vendor name from 8 fields in the CSV
The second hurdle is how to use that vendor name as a variable in a database query.
My third issue is what type of step to use for the database lookup.
I tried a dynamic SQL query, but I couldn't determine how to build the query using a variable, then how to pass the desired value to the variable.
The database table (VendorRatings) has 30 fields, one of which is vendor. The CSV also has 8 fields, one of which is also vendor.
My best effort was to use a dynamic query using:
SELECT * FROM VENDORRATINGS WHERE VENDOR = ?
How do I programmatically assign the desired value to "?" in the query? Specifically, how do I link the output of a specific field from Text File Input to the "vendor = ?" SQL query?
The best practice is a Stream lookup. For each record in the main flow (VendorRating) lookup in the reference file (the CSV) for the vendor details (lookup fields), based on its identifier (possibly its number or name or firstname+lastname).
First "hurdle" : Once the path of the csv file defined, press the Get field button.
It will take the first line as header to know the field names and explore the first 100 (customizable) record to determine the field types.
If the name is not on the first line, uncheck the Header row present, press the Get field button, and then change the name on the panel.
If there is more than one header row or other complexities, use the Text file input.
The same is valid for the lookup step: use the Get lookup field button and delete the fields you do not need.
Due to the fact that
There is at most one vendorrating per vendor.
You have to do something if there is no match.
I suggest the following flow:
Read the CSV and for each row look up in the table (i.e.: the lookup table is the SQL table rather that the CSV file). And put default upon not matching. I suggest something really visible like "--- NO MATCH ---".
Then, in case of no match, the filter redirect the flow to the alternative action (here: insert into the SQL table). Then the two flows and merged into the downstream flow.

Find and append text in all records of a table in SQL

I have a table called tabTranslations and I need to find all occurrences of a word and change it to something else(whilst preserving any other words in the record). Is this possible without changing every record manually? As this would take me forever.
For example let's say I wanted to find the word "value" in all the records and change it to "values", but there may be a record with the text "some text value" in which case I would want it to then read "some text values".
I only really know the very basics of SQL so I'm unsure if I can do this or how I would go about it.
This query should work.
update tabTranslations
set columnName = REPLACE(columnName,'value','values')

How to Add Long Text Column to Access Table Via Query

I am updating a table in a .mdb format Access database with Access 2013. I want to add a new field, lets say a Description field, to an existing table.
I can add a text column using the following query
ALTER TABLE TestTable ADD Description TEXT(255);
Alternatively I could use
ALTER TABLE TestTable ADD Description varchar(255);
This works fine, and adds a column to TestTable called Description that is limited to 255 characters. If I open the table in Design View, I can see that the type of Description is listed as "Short Text". However, there is an option there to have the field be of type "Long Text" which as far as I can tell doesn't have a character limit. It is easy to manually change the type from the Design View, but I want to know if I can do this via a query.
I tried increasing the character count in my original query like so
ALTER TABLE TestTable ADD Description TEXT(300);
But then I recieve the error "Size of field 'Description' is too long."
What I want to know is can I add the column via a query such that it has a character limit greater than 255? This query is run as part of a macro that is run automatically, so I don't want to have to change it manually. My attempts at searching for a solution via Google have so far come up empty.
Found the answer shortly after posting the question. Using the query
ALTER TABLE TestTable ADD Description LONGTEXT;
creates a new column of type "Long Text". It should be noted that a character count was not necessary for this type.

how to find a sql field name that has a record like '%text%'

i want to search all teh fields in my DB to find the field names that have in them a string that contains some text.
im trying to find a table and field responsible for some 3rd party software actions that i am aonly able to see the values for. i want to use these values to find the table and field they are stored in.
like this
select column_name,table_name
from information_schema.columns
where column_name like '%text%'
Misunderstood your question, see here: Search all columns in all the tables in a database for a specific value
This may help you:
http://blog.sqlauthority.com/2008/08/05/sql-server-2005-get-field-name-and-type-of-database-table/
I don't have specific answer.
But i use PHP code for MySQL that calls "show tables" and then for each table calls "show create table [table_name]"
I export the result to a text file and then search it...