+(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) ""))
+ (%%lrl (format nil " and ~:@(~A~) <= ~~D" lrlname))
+ (%%where (format nil " where ~:@(~A~)" where-name)))
+ `(concatenate
+ 'string
+ ,%%fields
+ ,@(when %%where (list %%where))
+ (if (quote ,where-name)
+ (format nil (if (stringp ,where-value)
+ (if ,like " like '%~A%'" "='~A'")
+ "=~A")
+ ,where-value)
+ "")
+ (if ,srl (format nil ,%%lrl ,srl) "")
+ ,@(when %%order (list %%order))
+ ,@(when single (list " limit 1")))))
+