Posts

Showing posts from February, 2020

SQL: Query to get the server Name in AS400

Current Server will give the server name of the as400 in which the query runs select current server from sysibm/sysdummy1 

SQL: To Identify a non-Numeric value in a Alpha Character Field

Below query will return the records that are having non numeric value in Field1 coumn. select * from Tbl1 where   translate(Trim(FIELD1), '         X',   '1234567890 ') <> ' '            translate(Trim(FIELD1), '         X',   ' 1234567890 ') Trim will remove trailing and leading spaces. Translate will translate FIELD1 values of 1, 2, 3, 4, ....0 to ' ' as mentioned (10 blanks one for each number, translation happens character by character) and the ' ' will be translated to X. Hence if a record has FIELD1 has numeric value all the numbers will be converted to blanks and ' ' inbetween will be converted to X. hence if there is a record that is non-blank which means it has non-numeric value which the translate couldn't convert Translate in update: Field1 = 1O5719374 update TBL1  set FIELD1 = translate(FIELD1, ' ','O')  where                                    FIELD2 = 15145