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 |
|
skillile
Posting Yak Master
208 Posts |
Posted - 2003-12-04 : 16:08:02
|
| CREATE TABLE #t (fn int, val varchar(100) , res varchar(7000),CONSTRAINT thecons PRIMARY KEY (fn,val) )INSERT INTO #t(fn,val) VALUES( 1, 'abc')INSERT INTO #t(fn,val) VALUES( 2, 'nmo')INSERT INTO #t(fn,val) VALUES( 1, 'def')INSERT INTO #t(fn,val) VALUES( 1, 'cpq')INSERT INTO #t(fn,val) VALUES( 2, 'yzz')SET NOCOUNT ONDECLARE @list varchar(8000), @x intSELECT @list = '', @x = -1UPDATE #t SET @list = res = CASE WHEN @x <> fn THEN val ELSE @list + ', ' + val END, @x = fnSELECT * FROM #tDROP TABLE #tThis is a cool post thanks page47[url]http://www.sqlteam.com/item.asp?ItemID=11021[/url]result set1 abc abc1 cpq abc, cpq1 def abc, cpq, def2 nmo nmo2 yzz nmo, yzzI only want the rows with the biggest res field ie.rows 3,5 returned.How can I query that?Thanksslow down to move faster... |
|
|
ehorn
Master Smack Fu Yak Hacker
1632 Posts |
Posted - 2003-12-04 : 17:20:55
|
| [code]select fn, max(val) val, max(res) resfrom #t agroup by fn[/code] |
 |
|
|
skillile
Posting Yak Master
208 Posts |
Posted - 2003-12-04 : 18:51:49
|
| Thank you very much :)slow down to move faster... |
 |
|
|
|
|
|
|
|