Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UK8Xi-0007z0-7Q for pgsql-sql@arkaria.postgresql.org; Mon, 25 Mar 2013 14:38:34 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UK8Xh-0002ZD-N1 for pgsql-sql@arkaria.postgresql.org; Mon, 25 Mar 2013 14:38:33 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UK8Xg-0002YN-EJ for pgsql-sql@postgresql.org; Mon, 25 Mar 2013 14:38:32 +0000 Received: from smtp43.kinghost.net ([189.38.82.43]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UK8XX-0002Z6-VO for pgsql-sql@postgresql.org; Mon, 25 Mar 2013 14:38:32 +0000 Received: from smtp-gw-01.kinghost.net (smtp-gw-01 [127.0.0.1]) by smtp43.kinghost.net (Postfix) with ESMTP id 82389C44E8; Mon, 25 Mar 2013 11:38:17 -0300 (BRT) Received: from sygecom.com.br (unknown [10.5.5.60]) by smtp-gw-01.kinghost.net (Postfix) with ESMTPA id 370BA22E35E46; Mon, 25 Mar 2013 11:38:17 -0300 (BRT) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Mon, 25 Mar 2013 11:38:17 -0300 From: Mauricio Cruz To: Pavel Stehule Cc: Subject: Re: From with case Organization: Sygecom In-Reply-To: References: <5ba0a01548c7c6540b1c693cdf7e979d@sygecom.com.br> Message-ID: <3a23e70c95dc9bb82ca19be4b9abed81@sygecom.com.br> X-Sender: cruz@sygecom.com.br User-Agent: RoundCube Webmail/0.4 Content-Transfer-Encoding: quoted-printable X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org Thanks very much Pavel, the dynamic SQL ideia has work perfect in my case. Thanks so much. --=20 Grato, Mauricio Cruz Sygecom Inform=C3=A1tica 51 3442-3975 / 3442-2345 On Mon, 25 Mar 2013 15:01:09 +0100, Pavel Stehule wrote: > Hello >=20 >=20 >> For rSql in select a.adiant, >> a.desc_per >> from case >> when cTip=3D'P' >> then valapag >> else valerec >> end >> where cod=3D2 Loop >=20 >=20 > you can use a dynamic SQL, but it is not best solution usually. In > this case I usually prefer >=20 > IF cTip =3D 'P' THEN > FOR r IN SELECT .. FROM valapag LOOP > PERFORM proc(r); > END LOOP; > ELSE > FOR r IN SELECT .. FROM valerec LOOP > PERFORM proc(r); > END LOOP; > END IF; >=20 > with dynamic SQL >=20 > FOR r IN EXECUTE format('SELECT .. FROM %I ..', CASE WHEN ctip =3D 'P' > THEN 'valapag' ELSE 'valerec' END) > LOOP > .. > END LOOP; >=20 > Regards >=20 > Pavel Stehule >=20 >=20 > 2013/3/25 Mauricio Cruz : >> Hi everyone, >> >> >> >> I'm working in a PL/SQL and I'd like to use the same PL for 2 kinds of >> tables... >> >> I have "valepag" and "valerec" both tables have the same columns, but on= e is >> for debit and the other one is for credit, the PL will work for both cas= es >> >> with the unique diference for the name of the table... >> >> >> >> So I thought to use something like this: >> >> ... >> >> For rSql in select a.adiant, >> a.desc_per >> from case >> when cTip=3D'P' >> then valapag >> else valerec >> end >> where cod=3D2 Loop >> >> >> >> ... >> >> >> But it just dont work... does some one have other solution for this case= ? >> >> >> >> Thanks guys. >> >> >> >> -- >> Grato, >> Mauricio Cruz >> Sygecom Inform=C3=A1tica >> 51 3442-3975 / 3442-2345 --=20 Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql