` Printed Icetips Article

Icetips Article



SQL Related Articles: Simple SELECT builder
2004-04-19 -- Juanro
 
Newsgroups: softvelocity.clarion.databasedrivers

Have you ever seen something like this?

Test FILE(...)
   Record
Field1   LONG
Field2   LONG
Desc    STRING
   END

Test{PROP:SQL} = 'SELECT Desc FROM Test WHERE ...'
!error: invalid character value ...

Do you have a file with a correct  ...PROP:SQL = 'SELECT ...' and then you
changed the file structure and "BANG!" ?

(I was. Many times )

Since then I'm using this (see below)
I guess many of you could have something similar, but anyway, here it is.
Hope you find it usefull, best regards,

Juanro

----------------------------------------------------------------------------
--------------------------------
BuildSelectList      PROCEDURE  (FILE ThisTable)           ! Declare
Procedure
LOC:StrLine          STRING(10000)                         !

  CODE
  LOC:StrLine = ''
  count# = 1
  LOOP f#=1 TO ThisTable{PROP:Fields}
     IF ThisTable{PROP:Type,f#}<>'GROUP'
        LOC:StrLine = CLIP(LOC:StrLine) & CHOOSE(count# > 1,',','') &
CLIP(UPPER(ThisTable{PROP:Name,f#}))
        count# += 1
     END
  END
  RETURN CLIP(LOC:StrLine)
----------------------------------------------------------------------------
------------------------------

Use it like this:

Test{PROP:SQL} = 'SELECT ' & BuildSelectList(Test) & ' FROM Test WHERE ...'



Printed May 5, 2024, 11:00 am
This article has been viewed/printed 35116 times.
Google search has resulted in 29 hits on this article since January 25, 2004.