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 2008 Forums
 Transact-SQL (2008)
 Several table rows (col value) in one gridview row

Author  Topic 

jbon
Starting Member

20 Posts

Posted - 2009-09-10 : 02:18:12
Hi,
I want to have data from several table rows into one gridview row, how can i do this?

For example I have one table as below

ID TYPE VALUE UNIT
-- ---- ----- ----
1 LMT 14 MTR
2 AAD 16854 KGM
3 VOL 23,34 MTQ
.. .. .. ...

These rows/values I want to have (display) in one gridview as follows

ID LMT (MTR) AAD (KGM) VOL (MTQ)
-- --------- --------- ---------
1 14 16854 23,34
.. .. .. ..

Any kind of advice is highly appreciated. Thanks in advance.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-09-10 : 02:23:36
[code]
SELECT ID,
[LMT(MTR)] = MAX(case when TYPE = 'LMT' then VALUE end),
[AAD(KGM)] = MAX(case when TYPE = 'AAD' then VALUE end),
[VOL(MTQ)] = MAX(case when TYPE = 'VOL' then VALUE end)
FROM yourtable
GROUP BY ID
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

jbon
Starting Member

20 Posts

Posted - 2009-09-10 : 03:56:13
Thx a lot it's working as I want... in SQL Server. Problem is that it is not working in Oracle, I guess because of different syntax. Is it anyone there that knows the Oracle syntax for this SQL query? Unfortunately I'm forced to contact a Oracle db for this information ;-)
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-09-10 : 04:34:53
try posting at dbforums.com


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -