I have a set of data coming in from a text file that looks like:
Date ID Value
01/01/2005 1 Value1
01/01/2005 2 Value2
01/01/2005 3 Value3
01/01/2005 4 Value4
01/01/2005 5 Value5
01/01/2005 6 Value6
01/01/2005 7 Value7
01/02/2005 1 Value1
01/02/2005 2 Value2
01/02/2005 3 Value3
01/02/2005 4 Value4
01/02/2005 5 Value5
01/02/2005 6 Value6
01/02/2005 7 Value7
There are 450 "ID"s per day and there will be ~30 days per month that
repeat these 450 IDs and values. I could potentially reduce this to
between 80 and 100 IDs. I would like to create a table that looks
like:
Date ID1 ID2 ID3 ID4 ID5 etc...
01/01/2005 Value1 Value2 Value3 Value4 Value5
01/02/2005 Value1 Value2 Value3 Value4 Value5
01/03/2005 Value1 Value2 Value3 Value4 Value5
What is the best way to do this? Any built-in SQL commands to assist?
Any tricks with DTS?
Thanks!
Dave 1 1286
<ni********@aol .com> wrote in message
news:11******** *************@c 13g2000cwb.goog legroups.com... I have a set of data coming in from a text file that looks like:
Date ID Value 01/01/2005 1 Value1 01/01/2005 2 Value2 01/01/2005 3 Value3 01/01/2005 4 Value4 01/01/2005 5 Value5 01/01/2005 6 Value6 01/01/2005 7 Value7 01/02/2005 1 Value1 01/02/2005 2 Value2 01/02/2005 3 Value3 01/02/2005 4 Value4 01/02/2005 5 Value5 01/02/2005 6 Value6 01/02/2005 7 Value7
There are 450 "ID"s per day and there will be ~30 days per month that repeat these 450 IDs and values. I could potentially reduce this to between 80 and 100 IDs. I would like to create a table that looks like: Date ID1 ID2 ID3 ID4 ID5 etc... 01/01/2005 Value1 Value2 Value3 Value4 Value5 01/02/2005 Value1 Value2 Value3 Value4 Value5 01/03/2005 Value1 Value2 Value3 Value4 Value5
What is the best way to do this? Any built-in SQL commands to assist? Any tricks with DTS?
Thanks! Dave
You're looking for a crosstab query: http://www.aspfaq.com/show.asp?id=2462
If the number of IDs is fixed, then a TSQL solution is possible (see below),
although with 450 IDs you might want to write a loop to generate the SELECT
statement. If things become more complex, or if the number of IDs can vary,
then it would be worth looking at a front-end solution or reporting tool.
Simon
select
date,
max(case when ID = 1 then Value else null end) as 'Value1',
max(case when ID = 2 then Value else null end) as 'Value2',
max(case when ID = 3 then Value else null end) as 'Value3',
...
from
dbo.MyTable
group by
date
order by
date This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Fabio |
last post by:
Hello,
is there any quite easy solution for the problem of transposing the rows
into the columns? I have the following table with some data in it:
dealer date 09.00 10.00 11.00 12.00 13.00 14.00
-----------------------------------------------------------------
1 2004-10-01 1/1 2/3 3/3 3/4 4/5 0/3
1 2004-10-02 0/1 1/3 1/3 1/4 3/5 1/3
|
by: Leszek Gruszka |
last post by:
Hello!
I need to transpose some columns into rows and rows into columns. I
know, tha i can do it by cursor, but i don't know how make it...
I read a lot about it, but still don't understand...
Can someone help me?
*** Sent via Developersdex http://www.developersdex.com ***
|
by: Christoph Lutz |
last post by:
Hi,
I would like to transpose a table in mysql. I have looked on the web for
a while but nothing seems to fit the bill, so I just want to clarify if
I have to write some php or if I can use a SQL query (preferred).
What I would like to do is to use the values in a row as column headings
during output, so that I can enter different sets of data into the same
table and display it in a readable format afterwards. Let me explain: I
have say...
|
by: Howard William |
last post by:
Help.
I am a bit flummoxed by the problem of how to transpose "normalized" (in the
database sense) data records into columns of for a data entry form, and then
back again when the user is finished.
My previous solution to this was to filter by query or SQL for the
observations for a particular set of criteria, then go through the resulting
records and assign them to a non-normalized work table containing ONE RECORD
with the rows x...
|
by: SakyMoto |
last post by:
I hope someone can help me with my problem. I have searched the
internet for days for a solution, but nothing i found seemed to work.
The following is what i have now:
appartmentid code
100306 Wip
100306 Zandbak
100306 Glijbaan
100306 Klimrek
100306 Schommel
| |
by: Classic-Car-World Ltd |
last post by:
Hi, I have some data in a table in columns which I need to convert into
rows. This is specification data for some tools etc. The data is currently
in the following format:
Product No, order, description, value
1000, 1, model No, Ak272
1000, 2, Size, 10mm
1000, 3, Length, 20mm
1001, 1, Model No, Ak273
|
by: Caspian |
last post by:
Dear All,
I'm attempting to create a query that will transpose repeated fields
into a single table structure. Can anyone think of how this can be done
as I'm stumped at the minute? I'd like to do this without having to
create a cursor due to the overheads and performance issues associated
with cursors. The table may also include additional fields which I'm
not interested in.
Serial Data is like this.............
|
by: m.wanstall |
last post by:
Hi there,
I have a large table based around a CustomerNumber with various details
about that customer (originally imported and augmented from an Exchange
Server)...now, a single customer can have many email addresses and thus
will have multiple entries in this table but this isn't what I want. Is
there a way to relatively simply take any duplicate CustomerNumber
records, take their EmailAddress field and append it in a new column...
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |