+(defmacro query-string-macro (table fields &optional srl where-name where-value
+ &key (lrlname "KCUILRL") single distinct order like)
+ (let* ((%%fields (format nil "select ~A~{~:@(~A~)~^,~} from ~:@(~A~)"
+ (if distinct "distinct " "") fields table))
+ (%%order (if order (format nil " order by ~{~:@(~A~) ~(~A~)~^,~}" order) "")))
+ `(concatenate
+ 'string
+ ,%%fields
+ (if ,where-name
+ (format nil
+ (if (stringp ,where-value)
+ (if ,like
+ " where ~A like '%~A%'"
+ " where ~A='~A'")
+ " where ~A=~A")
+ ,where-name ,where-value)
+ "")
+ (if ,srl (format nil " and ~:@(~A~) <= ~D" ,lrlname ,srl) "")
+ ,%%order
+ (if ,single " limit 1" ""))))
+