ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

field name as variable

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

  • field name as variable

    Here's a sample of using embedded SQL to retrieve the value of a database field when the field name comes from another variable:
    PHP Code:
         D FieldName       s             10A
         D Stmt            s            500A
         D Result          s             50A

         C     
    *ENTRY        PLIST
         C                   PARM                    Field            10

         C                   
    EVAL      Stmt 'SELECT ' + %trimr(Field)
         
    C                                  ' from CUSTMAS'
         
    c                                  ' where CUSTNO=1316'

         
    C/exec sql          set option naming=*sys
         C
    /end-exec
         C
    /exec sql          prepare sqlstmt from :stmt
         C
    /end-exec
         C
    /exec sql          declare C1 cursor for sqlstmt
         C
    /end-exec
         C
    /exec sql          open C1
         c
    /end-exec
         C
    /exec sql          fetch from C1 into :Result
         c
    /end-exec
         C
    /exec sql          close C1
         c
    /end-exec

         C                   dsply                   Result
         C                   
    eval      *inlr = *ON 
    I'm here to chew bubble gum and kick @#%@#%@#%.....and I'm all outta bubble gum !
    Yes I'm talking to you squirrel nuts.
Working...
X