473,587 Members | 2,501 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to create table using result of previous query as column name ?

15 New Member
I have table as Table1
p_cd dt qty price amt
001 12/13/2009 10 20 200
002 12/14/2009 5 10 50
001 12/15/2009 10 20 200
001 12/19/2009 8 20 160
i want result as
p_cd 12/13/2009 12/14/2009 12/15/2009 12/19/2009 totqty price amt
001 10 - 10 8 28 20 560
002 - 5 - - 5 10 50
Dec 30 '09 #1
4 1840
Mangala Teli
15 New Member
How to create table using result of previous query as column name ?
Dec 30 '09 #2
ChipR
1,287 Recognized Expert Top Contributor
Have you created tables or stepped through recordsets with VBA before? Also, why would you want to do this? You seem to be taking correctly normalized data and storing it in a way that is not dynamic.
Dec 30 '09 #3
ADezii
8,834 Recognized Expert Expert
I do believe that a Crosstab Query will produce the results you seek:
Expand|Select|Wrap|Line Numbers
  1. TRANSFORM Sum(Table1.qty) AS SumOfqty
  2. SELECT Table1.p_cd, Sum(Table1.qty) AS [Total Quantity],
  3. Sum(Table1.price) AS [Total Price], 
  4. Sum(Table1.amt) AS [Total Amount]
  5. FROM Table1
  6. GROUP BY Table1.p_cd
  7. PIVOT Format([dt],"Short Date");
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. p_cd    Total Quantity    Total Price    Total Amount    12/13/2009    12/14/2009    12/15/2009    12/19/2009
  2. 001            28          $60.00           560              10                           10          8
  3. 002             5          $10.00            50                            5    
Dec 31 '09 #4
NeoPa
32,566 Recognized Expert Moderator MVP
ADezii has provided code to show how the data can be formatted as requested. Chip makes a good point though. De-normalising your data is not generally recommended. If you need to though, it is a simple step to convert SQL similar to what ADezii's posted into a Make Table query. Remember we warned against such a step though.
Jan 6 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
21340
by: Thomas Jerkins | last post by:
When I write a create table SQL statement I want to add some information about the column heading of each column. How does the exact syntax for the create table look like (which includes this column data look)? How do I add later column headings ? Tom
6
12269
by: Bruce | last post by:
I want to create a new table based on an existing table, but I don't want the tables to have any enforced relationship. Is this possible without having to do a CREATE TABLE and an INSERT? create table customer_Temp as (select credit_Card_number, personal_id_number from customer) DATA INITIALLY DEFERRED REFRESH deferred; refresh table...
6
8510
by: Rudolf Bargholz | last post by:
Hi , I have the following tables ------------- PAX: Id Order_Id Name Position
3
1375
by: jaYPee | last post by:
I'm so sorry for posting this message again 'cause there's a lot of error in my previous posting... I'm having problem w/ my query on how to filter a record based on the criteria i give. here's the tables students table id
10
8788
by: Zack Sessions | last post by:
Has anyone tried to create a SQL7 view using the CREATE VIEW command and ADO.NET? If so, is there a trick in trapping a SQL error when trying to create the view? I have a VB.NET app that, amoung other things, can create views based on existing tables and a table of column name equivalents. If I accidently introduce a column name equivalent...
18
6626
by: PC Datasheet | last post by:
An Access user saw my name in a newsgroup and sent me a request for help on a project. As part of the project, a list of the dates in a month was needed. For anyone needing a list of dates in a month, here is what I used: 1. Create a table named TblNumbers with one field named Num and populate the table with 1 to 31 2. Create a query...
1
3901
by: JackM | last post by:
I'm not sure if this qualifies as a mysql or a php question so I'm asking in both groups. I am pulling the results of a mysql query from my database and want to print the results into a two column table. I know how to get the results into a single column table just fine using: while($row = mysql_fetch_array($result)) { print "<table...
10
13396
by: eholz1 | last post by:
Hello Members, I am setting up a photo website. I have decided to use PHP and MySQL. I can load jpeg files into the table (medium blob, or even longtext) and get the image(s) to display without a problem. I am using chunk_split(data) and the base64_encode and base64_decode on the files. I do a select from the database, and then echo the...
7
4099
by: Lucas_london via AccessMonster.com | last post by:
Hi I have set up a database/tables in Access based on daily timeseries data. However I would like to create two additional columns in the table as a basis to pull the data on a weekly and monthly series basis. Currently, in excel I am using the weekday and EOMONTH functions to create the flags/indicator in my excel dataset: (Cells in...
3
18699
by: creative1 | last post by:
Here is how you create a complex data report that involves parent and child commands and you can update information at runtime. Its pretty straight forward to work with simple queries; however, working with complex reports is tricky Assumption: Reader of this article have basic knowledge of creating data reports. Creating a Parent-Child...
0
7920
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8347
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5718
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3844
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1454
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1189
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.