[SQL] a way to generate functions dynamically ?

2007-01-11 Thread Marc Mamin
Hello, I need to generate some procedures that depend data models stored in my DBs. As I have different models in different databases, the stored procedures will differ. My idea is to generate the required stored procedures dynamically once a model is defined. I will probably do this within

Re: [SQL] a way to generate functions dynamically ?

2007-01-11 Thread Richard Huxton
Marc Mamin wrote: Hello, I need to generate some procedures that depend data models stored in my DBs. As I have different models in different databases, the stored procedures will differ. My idea is to generate the required stored procedures dynamically once a model is defined. I will

[SQL] Aggregating both tables in a join?

2007-01-11 Thread Steve Sabljak
Hi, I've got a table which models the relationship between flights and legs, which is defined like this:- create table flight_leg ( flight_id integer references flight(id), leg_id integer references leg(id) ); One leg may be part of many flights and one flight may be made up of 1 or more

Re: [SQL] How to aggregates this data

2007-01-11 Thread Bruno Wolff III
On Thu, Jan 11, 2007 at 07:50:19 +0900, John Summerfield [EMAIL PROTECTED] wrote: I've perused my book (Mastering SQL by Martin Gruber), the postgresql docs (I have versions here on RHEL (Centos) 4, FC5,6, Debian Testing - up to 8,1) and I don't see how to choose the entry for the first

Re: [SQL] Aggregating both tables in a join?

2007-01-11 Thread Aaron Bono
On 1/11/07, Steve Sabljak [EMAIL PROTECTED] wrote: select cf.flight_id, tl1.num_legs, cf.cmp_flight_id, tl2.num_legscmp_num_legs from cmp_flight cf join (select fl1.flight_id fid1, count(*) num_legs from flight_leg fl1 group by fl1.flight_id) tl1 on fid1 = cf.flight_id join

[SQL] Conditional SQL Query

2007-01-11 Thread devil live
I want to write sql statement about product, product_tree_special, product_tree_template product has product_code varchar(20) PRIMARY KEY, product_name varchar(20) product_tree_template has product_code varchar(20) PK, stock_code_to_make_product(20) PK, amout float4

Re: [SQL] Conditional SQL Query

2007-01-11 Thread M.P.Dankoor
I think that the simplest solution is to use an union e.g: select PRD.product_code ,PRD.product_name ,NULL::intAS production_no ,PTT.stock_code_to_make_product ,PTT.amount from product PRD ,product_tree_template PTT where 1 = 1 AND PRD.product_code =

Re: [SQL] Conditional SQL Query

2007-01-11 Thread Chad Wagner
On 1/11/07, devil live [EMAIL PROTECTED] wrote: NOW : product_tree_template table is the default table for production ingredients of the PRODUCT but sometimes my customer using special product_tree table for some production_no how can I write a query to get right ingredients of a product

Re: [SQL] Conditional SQL Query

2007-01-11 Thread Shane Ambler
M.P.Dankoor wrote: devil live wrote: how can I write a query to get right ingredients of a product basis on production_no field such as; first check production_no if product_tree_special table if not found then look at template table... What are your suggestions? I think M.P.