ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

trimming field value

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Ok, so now how to resolve this 'syntax error like 'token <end of statement> was not valid valid tokens 0 ,'


    Thanks

    Comment


    • #17
      Originally posted by John192 View Post
      i am getting syntax error like 'token <end of statement> was not valid valid tokens 0 ,

      i tried this
      CREATE VIEW QTEMP/FILE3 > ( FLD1 , FLD2 , FLD3 , FLD4 ) AS > ( SELECT A.FLD1 , A.FLD2 , B.FLD1 , B.FLD2 > FROM QTEMP/FILE1 a > JOIN QTEMP/FILE2 b > ON on A.FLD1 = INT(NULLIF(REGEXP_REPLACE(B.FLD1,'[^0-9]',''),''))

      Thanks
      What is the purpose of the '>' in your code ?
      Last edited by MFisher; June 24, 2022, 07:02 AM.

      Comment


      • #18
        it did not appear here when I copied it from my last (post #10) adding that suggested regular expression may be because I missed to use code blocks for this SQL query :-

        [code ]


        CREATE VIEW mylib/FILE3 ( FLD1 , FLD2 , FLD3 , FLD4 ) AS ( SELECT A.FLD1 , A.FLD2 , B.FLD1 , B.FLD2) FROM LIBa/FILE1 a JOIN LIBb/FILE2 b ON
        A.FLD1 = INT(NULLIF(REGEXP_REPLACE(B.FLD1,'[^0-9]',''),''))

        [/code]


        I am using above SQL query for join in my SQL/400 green screen ,and getting that error -'syntax error like 'token <end of statement> was not valid valid tokens 0 ,'




        Thanks

        Comment


        • #19
          You changed your parentheses from the post 10 version.

          Comment


          • #20
            Ok, thanks now this view file3 got created in my library but when I ran sql query select * from mylib/file3 I am getting results like:-

            FLD1 (File1) FLD1(File2)

            12 ABCDE012

            5,678 XY005678


            1 001 J


            1 001

            1 ABCDEFG1


            So though matching numeric number from field1 of file 2 is getting displayed here but again with the unwanted text along with it like in above examples (for 5678 - XY is unwanted and for 12 that ABCDE is unwanted and for 1 those 5 blanks between 001 and J are unwanted) is getting displayed in the Query result on the screen.



            Thanks

            Comment


            • #21
              When you create a View, do you give it a name that identifies that it is a view, and not a file ? Such a VIEW3 ?
              It is confusing to have you refer to file3, that is a view.
              Last edited by MFisher; June 24, 2022, 07:50 AM.

              Comment


              • #22
                yes i created it as a view only but in my own library.

                Comment


                • #23
                  I am active on a SQL Server forum. They are pretty insistent that when this type of troubleshooting help is requested, the requester post the File creation statements, and sample data insert statements, so that others can easily recreate the same scenario by copy-pasting into their own system and all looking at and working with the same data.

                  Try to visualize and write your posts from the perspective of someone not familiar with your files and data.
                  That also includes formatting your posts so the code and data are easy to read.
                  Last edited by MFisher; June 24, 2022, 07:54 AM.

                  Comment


                  • #24
                    Isn't it selecting the fields that you asked for?

                    Code:
                    SELECT A.FLD1 , A.FLD2 , B.FLD1 , B.FLD2
                    Last edited by MFisher; June 24, 2022, 08:21 AM.

                    Comment


                    • #25
                      File1 ( have field1 let's say it's name is X - Data type Decimal length 6, it has other fields as well but we are currently not bothered about those fields)

                      file2( have fiield1 let's say it's name is Y- Data type is Character with 9 length - it too have other fields in this file but currently we are not bothered about those fields)


                      Just for example some dummy Data in File1's field X:-

                      1) 2044
                      2) 32,018
                      3)106



                      Just for example some dummy Data in File2's field Y:-

                      *
                      *B
                      *END
                      001 F
                      001 V
                      *
                      *
                      ZC057882
                      ZD071304
                      ZW002711
                      ABCDE


                      So the requirement is to join these two fields ( of these two files) in such a way that for that the number( whose max length is 6 and data type is decimal) in this field X we have to find it's corresponding match in Field Y ( of file2) provided when we search a match in Field Y ( of file2) then we should extract only the equivalent number part from file2's field Y.

                      So If I get below kind of records :-

                      field X field Y

                      2044 000002044 ----it's fine.
                      2044 00space2044 ---it's not fine
                      2044 2044ABCDE ---it's not fine



                      Thanks


                      Comment


                      • #26
                        Originally posted by MFisher View Post
                        Isn't it selecting the fields that you asked for?

                        Code:
                        SELECT A.FLD1 , A.FLD2 , B.FLD1 , B.FLD2
                        it does select but I don't get the result which I want as I explained it in my post #25



                        Thanks

                        Comment


                        • #27
                          Your SELECT asks for the fields as they are in the file. If you want modified results, modify your SELECT.
                          Last edited by MFisher; June 24, 2022, 09:08 AM.

                          Comment


                          • #28
                            i have modified it even though it does not display the matching records the way i want as explained in post #25

                            thanks

                            Comment


                            • John192
                              John192 commented
                              Editing a comment
                              for this i meant to say for my post #20 though i was able to view fields as per my selection but as i showed it's not showing the data in acceptable format i mean it showed like mentioned earlier -FLD1 (File1) FLD1(File2)

                              12 ABCDE012

                              5,678 XY005678

                              which is not acceptable as per explanation in my post #25

                              thanks

                          • #29
                            You have a simple SELECT of the fields. Modify the SELECT to present the fields in the format you want.

                            Comment


                            • #30
                              How to modify to get desired result so that i just get records matching as per explanation in my Post #25

                              Thanks

                              Comment

                              Working...
                              X