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