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.
Author |
Topic |
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-08-07 : 13:59:54
|
Kathy writes "Can any one please help me in creating queryActual Data in databaseID Name Award Note91 Maxine Ace Award Give on date 23rd February.91 Maxine Ace Award Give on date 27th January.91 Maxine Meal Voucher Give on date 5th June.91 Maxine Meal Voucher Give on date 8th August.92 Collette Ace Award Give on date 2nd January.92 Collette Ace Award Give on date 3rd March.92 Collette Ace Award Give on date 5th July92 Collette Ace Award Give on date 9 April92 Collette Meal Voucher Give on date 8th November.92 Collette Meal Voucher Give on date 7th June.92 Collette Meal Voucher Give on date 4th July.Required DataID Name Award No of Times Note91 Maxine Ace Award 2 Give on date 23rd February.Give on date 27th January.91 Maxine Meal Voucher 2 Give on date 5th June.Give on date 8th August.92 Collette Ace Award 3 Give on date 2nd January.Give on date 3rd March.Give on date 5th July92 Collette Meal Voucher 3 Give on date 8th November.Give on date 7th June.Give on date 4th July.Thanks," |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-08-08 : 12:54:21
|
[code]-- prepare test datadeclare @test table (id int, name varchar(100), note varchar(100))insert @testselect 91, 'Maxine Ace Award', 'Give on date 23rd February.' union allselect 91, 'Maxine Ace Award', 'Give on date 27th January.' union allselect 91, 'Maxine Meal Voucher', 'Give on date 5th June.' union allselect 91, 'Maxine Meal Voucher', 'Give on date 8th August.' union allselect 92, 'Collette Ace Award', 'Give on date 2nd January.' union allselect 92, 'Collette Ace Award', 'Give on date 3rd March.' union allselect 92, 'Collette Ace Award', 'Give on date 5th July' union allselect 92, 'Collette Ace Award', 'Give on date 9 April' union allselect 92, 'Collette Meal Voucher', 'Give on date 8th November.' union allselect 92, 'Collette Meal Voucher', 'Give on date 7th June.' union allselect 92, 'Collette Meal Voucher', 'Give on date 4th July.'-- do the workdeclare @stage table (id int, name varchar(100), notes varchar(8000))insert @stageselect distinct id, name, ''from @testdeclare @id int, @notes varchar(8000)select @id = min(id), @notes = ''from @stagewhile @id is not null begin select @notes = left(@notes + note, 8000) from ( select top 100 percent note from @test order by id ) z update @stage set notes = notes + @notes select @id = min(id), @notes = '' from @stage where id > @id end-- show the outputselect * from @stage[/code]Peter LarssonHelsingborg, Sweden |
|
|
|
|
|
|
|