Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7047133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:44:03+00:00 2026-05-28T02:44:03+00:00

I have table data, select * from tbltaxamount ; id | taxname | taxinfoid

  • 0

I have table data,

select * from tbltaxamount ;
 id |   taxname   | taxinfoid | taxvalue | taxamt | zoneid | invoiceid | transid 
----+-------------+-----------+----------+--------+--------+-----------+---------
  1 | Service Tax |         0 |     0.00 |  28.69 |      2 |       119 |      -1
  2 | ABC Tax     |         0 |     0.00 |  25.78 |      2 |       119 |      -1

Now, how can I get the result as below using any function of PostgreSQL?

invoiceid | Service Tax | ABC Tax
----------+-------------+--------
      119 |       28.69 |  25.78
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:44:03+00:00Added an answer on May 28, 2026 at 2:44 am

    After so may tries I have created below function for creation of the table on the fly and that will display records as above.

    CREATE OR REPLACE FUNCTION taxamount() RETURNS void as $$
    DECLARE
            columnNames RECORD;
        invoiceids RECORD;
    BEGIN
        FOR columnNames IN  SELECT * from pg_tables where tablename = 'tmptable'
            LOOP
                DROP TABLE tmptable ;        
            END LOOP;
        CREATE TABLE tmptable (invoiceid integer PRIMARY KEY);
        FOR columnNames IN SELECT distinct(replace(taxname,' ','')) as taxnames from tbltaxamount
            LOOP
                    EXECUTE 'ALTER TABLE tmptable ADD ' || columnNames.taxnames || ' numeric(9,2) DEFAULT 0';
            END LOOP;
        FOR invoiceids IN SELECT distinct(invoiceid) from tbltaxamount
        LOOP
            EXECUTE 'INSERT INTO tmptable (invoiceid) VALUES (' || invoiceids.invoiceid || ')';
        END LOOP;
        FOR invoiceids IN SELECT * from tbltaxamount
        LOOP
            EXECUTE 'UPDATE tmptable SET ' || replace(invoiceids.taxname,' ','') || ' = ' || invoiceids.taxamt  || ' WHERE invoiceid = ' || invoiceids.invoiceid;
        END LOOP ;
    RETURN;
    END;
    $$ LANGUAGE plpgsql;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table full of data called MYTABLE I used SELECT * FROM
Let's assume we have MySQL table events from which we'll select a data. Now
I have a table that I select data from with a column called parent
I have table rows of data in html being filled from a CGI application.
I have a table of data sorted by date, from which a user can
Alright, so I have a table outputting data from a MySQL table in a
I have a simple table of data, and I'd like to select the row
I have this output from SQL table: array{ data => line1 line2 line3 }
I have three table.2 data comes from 2 table and insert it into another
I have the following Execution statement which creates a table (using data from another

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.