Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Select the same field multiple times, different criteria

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-05-03 : 13:06:32
TomArgh writes "Hi,

I am trying to query the same field in a table multiple times, each time returning the field AS [a new name] with each instance of the field matching a different WHERE criteria for the time field.

I have a table collecting data on an hourly basis, I want to construct a query that returns the data broken down into hours over the day, as shown below.

Table...

ID DataSource Time Value
1 Source1 12:00 15
2 Source1 13:00 10
3 Source2 13:00 11
4 Source1 14:00 12
5 Source2 14:00 9


SQL output required....

DataSource hour12 hour13 hour14 hour15 ..etc
Source1 15 10 12
Source2 11 9


Thanks for your thoughts...
(SQL server 7)"

MichaelP
Jedi Yak

2489 Posts

Posted - 2004-05-03 : 13:35:00
Do a search on Dynamic Crosstab on the main site. That's what you are looking for.

Enjoy!

Michael

<Yoda>Use the Search page you must. Find the answer you will.</Yoda>
Go to Top of Page
   

- Advertisement -