Concatenating parts of sql queris

I’m trying to develop a full-text search filtered by location and
categories!
My ugly way is to write different sql query’s for different solution,
but i realize that is just stupid and ugly and didn’t do the job!
Nifty_scaffold don’t work for me, i need the custom job!
Are concatenating the parts of sql is hard in ruby?
Can someone pass the link of tutorial or solution to this problem of
mine?
Thanks in advance!

Are you talking about doing Unions in SQL?
Or do you have multiple distinct results from different tables that
you want to aggregate?

Jorg L. wrote:

Are you talking about doing Unions in SQL?
Or do you have multiple distinct results from different tables that
you want to aggregate?

Jorg
I’m talking about setting up a parts of sql like
var1 = SELECT
jobs.id,
jobs.location,
jobs.title,
jobs.company,
jobs.description,
jobs.url
FROM
jobs
var2 = WHERE
jobs.id > 0
AND jobs.id = jobs_categories.job_id

var3 = ta na na na GROUP BY categories.id
ORDER BY categories.name ASC

and if defined?(some_value) then
query = var1+vart3
else
 !defined?(some_value) then
 query = var1+vart2+var4
else
 !defined?(some_value) then
 query = var1+vart3+var4
end
something like that!
Or if u have a bather solution I'm listening! :)
Thanks!

Oh I see. That’s what I do. I actually have a model (not an active
record base) that just generates SQL and it does exactly what you
have. Input depends on the specific function, the pieces are added
with ruby and the final sql in returned. Then I just access the
methods from whatever controller needs them. It keeps all the sql
generation in one place.

Jorg L. wrote:

Oh I see. That’s what I do. I actually have a model (not an active
record base) that just generates SQL and it does exactly what you
have. Input depends on the specific function, the pieces are added
with ruby and the final sql in returned. Then I just access the
methods from whatever controller needs them. It keeps all the sql
generation in one place.
Sounds cool and clean.
Can you tell me hay u do it please.
thanks!