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)
 SQL doubt

Author  Topic 

jeusdi
Starting Member

27 Posts

Posted - 2006-10-05 : 10:41:18
Hello, I have a sentence how this:

SELECT NUM_FIGURES, PERIMETER, PRICE FROM PRICE_LIST

and the result is a "table" seems to:

NUM_FIGURES PERIMETER PRICE
1 25 123
1 50 180
1 75 200
2 25 130
2 50 180
2 75 230

,but I would like me get a "table" how:

25 50 75
----------------------
1 123 180 200
2 130 180 230

Does exist any form to get this type of "table" using SQL directly?

Note: PRICE_LIST TABLE STRUCTURE

CREATE TABLE PRICE_LIST (
NUM_FIGURES INTEGER,
PARIMETER INTEGER,
PRICE REAL
);

Thanks for all in advanced

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-10-05 : 10:52:02
[code]
select NUM,
[25] = max(case when PERIMETER = 25 then PRICE end),
[50] = max(case when PERIMETER = 50 then PRICE end),
[75] = max(case when PERIMETER = 75 then PRICE end)
from PRICE_LIST
group by NUM
[/code]



KH

Go to Top of Page

jeusdi
Starting Member

27 Posts

Posted - 2006-10-05 : 11:00:11
Exceuse me to forget a little big thing:

25,50 and 75 can be any value, you can replaced them by x, y and z or a,b,c,d,e. Is my question possible?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-10-05 : 11:03:07
quote:
Originally posted by jeusdi

Exceuse me to forget a little big thing:

25,50 and 75 can be any value, You can be replaced by x, y and z or a,b,c,d,e. Is my question possible?



just replace with variable

select NUM,
[col1] = max(case when PERIMETER = @x then PRICE end),
[col2] = max(case when PERIMETER = @y then PRICE end),
[col3] = max(case when PERIMETER = @z then PRICE end)
from PRICE_LIST
group by NUM



KH

Go to Top of Page

jeusdi
Starting Member

27 Posts

Posted - 2006-10-05 : 11:10:32
Mmm, for example:
select NUM,
[col1] = max(case when PERIMETER = @x then PRICE end),
[col2] = max(case when PERIMETER = @y then PRICE end),
[col3] = max(case when PERIMETER = @z then PRICE end)
from PRICE_LIST
group by NUM

My case is
Mmm, for example:
select NUM,
[col1] = max(case when PERIMETER = @x then PRICE end),
[col2] = max(case when PERIMETER = @y then PRICE end),
[col3] = max(case when PERIMETER = @z then PRICE end)
... I don't know how much columns there are?
from PRICE_LIST
group by NUM

And @x,@y,@z neither. They depends of supplier

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-10-05 : 11:54:36

http://weblogs.sqlteam.com/jeffs/archive/2005/05.aspx


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -