Author |
Topic |
masterdineen
Aged Yak Warrior
550 Posts |
Posted - 2013-02-26 : 07:03:08
|
hello there.i have a table with multiple instances of the example below.ref 1 2 3 4 5140622 1 1 0 0 0140622 0 0 0 1 0140622 0 0 0 0 1140623 0 0 1 0 0140623 0 0 0 1 0140623 1 1 0 0 0how could i consolidate into on line per ref?RegardsRob |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2013-02-26 : 07:07:45
|
select max([1]),max([2]),max([3]),max([4]),max([5]) from table group by ref Too old to Rock'n'Roll too young to die. |
|
|
masterdineen
Aged Yak Warrior
550 Posts |
Posted - 2013-02-26 : 07:36:57
|
thank you for your reply,i have maxed all my number columns. but iget the below.client_ref 1 2 3 4 51000 1 1 1 1 110000 1 1 1 1 1100000 1 1 1 1 1100001 1 1 1 1 1100004 1 1 1 1 1100005 1 1 1 1 1100006 1 1 1 1 1100009 1 1 1 1 1i want to include 0's when there are some. |
|
|
masterdineen
Aged Yak Warrior
550 Posts |
Posted - 2013-02-26 : 07:39:32
|
for examplethe below 140623 0 0 1 0 0140623 0 0 0 1 0140623 1 1 0 0 0will become140623 1 1 1 1 0 |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-02-26 : 08:16:37
|
Once execute thisDECLARE @tab TABLE(ref INT, [1] INT, [2] INT, [3] INT, [4] INT, [5] INT)INSERT INTO @tabSELECT 140622, 1, 1, 0, 0, 0 UNION ALLSELECT 140622, 0, 0, 0, 1, 0 UNION ALLSELECT 140622, 0, 0, 0, 0, 1 UNION ALLSELECT 140623, 0, 0, 1, 0, 0 UNION ALLSELECT 140623, 0, 0, 0, 1, 0 UNION ALLSELECT 140623, 1, 1, 0, 0, 0select ref, max([1]),max([2]),max([3]),max([4]),max([5]) from @tab group by ref--Chandu |
|
|
masterdineen
Aged Yak Warrior
550 Posts |
Posted - 2013-02-26 : 08:23:39
|
isnt that just the same as select max([1]),max([2]),max([3]),max([4]),max([5]) from table group by refi already have the data in a table |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2013-02-26 : 08:33:43
|
yes it is the same and it shows you that it works! Too old to Rock'n'Roll too young to die. |
|
|
masterdineen
Aged Yak Warrior
550 Posts |
Posted - 2013-02-26 : 11:01:07
|
My data is aready in a table, so unable to us union all, i want to be able to query directly to table |
|
|
masterdineen
Aged Yak Warrior
550 Posts |
Posted - 2013-02-26 : 11:48:21
|
sorted it, thank you for your help |
|
|
|
|
|