[SQL] A better look at trying to insert a Conditional in a SELECT statement

2007-07-17 Thread Norm Garand
Hi Again: thanks to those who sent me responses on my first post. I'll try to explain a bit better. There are several parameters that are passed by the user. Each of the parameters that are being passed, may have a NULL value, or an actual numerical value. The parameters filter a large report d

Re: [SQL] Inserting an IF statement in the middle of a SELECT in pl/pgSQL code

2007-07-17 Thread Jaime Casanova
On 7/17/07, Norm Garand <[EMAIL PROTECTED]> wrote: In the WHERE portion of the SELECT statment, I'd like to insert the IF statement shown below. I've tried single and double quotes and the pipeline for concatenation, but nothing seems to work. Any suggestions or resolutions would be greatly app

Re: [SQL] Inserting an IF statement in the middle of a SELECT in pl/pgSQL code

2007-07-17 Thread Rodrigo De León
On 7/17/07, Norm Garand <[EMAIL PROTECTED]> wrote: /--- IF $7 IS NOT NULL THEN AND f.id = pid.specific_location_cid AND f.long_desc = $7 END IF ---/ How about: AND f.ID = pid.specific_location_cid AND f.long_desc = COALESCE ($7, f.long_desc) ---

[SQL] Inserting an IF statement in the middle of a SELECT in pl/pgSQL code

2007-07-17 Thread Norm Garand
Hi: I can't seem to resolve this issue. I have a fair sized SELECT statement that runs properly in a stored procedure using pl/pgSQL, but I have certain parts of the query that can filter by a NULL value, or a character string. What I can't seem to do is insert a conditional IF statement in my c

Re: [SQL] data dependent sequences?

2007-07-17 Thread Andrew Sullivan
On Tue, Jul 17, 2007 at 12:23:21PM -0600, Stuart wrote: > > Except that the value does matter outside of the database and thus > needs to be remembered. It is not used for ordering at all. If you have two rows of data, where one column is data that varies as a function of the data in some other

Re: [SQL] data dependent sequences?

2007-07-17 Thread Stuart
"Andrew Sullivan" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On Tue, Jul 17, 2007 at 09:40:21AM -0600, Stuart wrote: > > is not really structually important -- it is a value that > > exists soley for the UI. > > Hmm. Maybe you should use generate_series() for the UI instead

Re: [SQL] data dependent sequences?

2007-07-17 Thread Andrew Sullivan
On Tue, Jul 17, 2007 at 09:40:21AM -0600, Stuart wrote: > is not really structually important -- it is a value that > exists soley for the UI. Hmm. Maybe you should use generate_series() for the UI instead? It would always give you the order you like, you could use the universal sequence or w

Re: [SQL] data dependent sequences?

2007-07-17 Thread Stuart
"Andrew Sullivan" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On Tue, Jul 17, 2007 at 07:34:26AM -0600, Stuart wrote: > > I am not looking for gapless sequences. The reason I > > want to do this is the "typ" column is actually an indicator > > of the source of the rest of the in

Re: [SQL] data dependent sequences?

2007-07-17 Thread Andrew Sullivan
On Tue, Jul 17, 2007 at 07:34:26AM -0600, Stuart wrote: > I am not looking for gapless sequences. The reason I > want to do this is the "typ" column is actually an indicator > of the source of the rest of the infomation in the row. Why do you need the sequence to be 1. . .n for each typ, then? I

Re: [SQL] data dependent sequences?

2007-07-17 Thread Richard Broersma Jr
--- Stuart <[EMAIL PROTECTED]> wrote: > > you will need to use pre insert trigger since you cannot use column > > references in default expression. > > > > you could use this same trigger to either: > > - create sequences as needed and apply the right one > > - with locking, lookup for last id of

Re: [SQL] data dependent sequences?

2007-07-17 Thread Stuart
"chester c young" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > > > CREATE TABLE items ( > > id INT, > > typ INT... > > PRIMAY KEY (seq,typ)); > > > > >id typ > > +- > > 1 'a' > > 2 'a' > > 3 'a' > > 1 'b' > > 4 'a'

Re: [SQL] data dependent sequences?

2007-07-17 Thread Stuart
"Ragnar" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On sun, 2007-07-15 at 09:28 -0600, Stuart McGraw wrote: > > Advice requested :-) I have a table like: > > > > CREATE TABLE items ( > > id INT, > > typ INT... > > PRIMAY KEY (seq,typ)); > > > > I would like 'i

Re: [SQL] Having the sum of two queries

2007-07-17 Thread Dani Castaños
Thank you all! My problem has been solved in another way... because the inner queries had left outer joins and so on, and I finally have had to do two queries and treat results by PHP. Again... thank you all! ---(end of broadcast)--- TIP 2: Don'