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 |
|
OldMySQLUser
Constraint Violating Yak Guru
301 Posts |
Posted - 2007-11-26 : 05:10:04
|
| I have a table containing the following columns:boxes quantity item price------ --------- ----- -----2 12 shirts 2.901 24 pants 3.1010 24 shirts 2.853 12 caps 1.904 36 socks 1.0012 36 shirts 2.908 24 shirts 2.90I need to select, say, shirts and display the sum ofboxes and quantity for each price level of shirts giving also the box count(s) (quantity)that they are available in like so:ShirtsPrice Box count Stock level2.90 12/24/36 6482.85 24 240How can I do this please? |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
OldMySQLUser
Constraint Violating Yak Guru
301 Posts |
Posted - 2007-11-26 : 06:22:40
|
Many thanks khtan. I shall now attempt my first function.Hold tight everyone, here we go! |
 |
|
|
OldMySQLUser
Constraint Violating Yak Guru
301 Posts |
Posted - 2007-12-05 : 11:59:56
|
| I'm making a mess of this right now.My select statement is:SELECT retail, supplier, total, boxes = dbo.fn_concat_boxes(item, price) from flexing_stock_transactions WHERE (item = 'shirt' AND week = 35 AND firm_or_commission = 'C') group by retail, supplier, total ORDER BY retail DESCI created a function so:CREATE FUNCTION fn_concat_boxes(@item varchar, @price int)RETURNS VARCHAR(200)ASBEGINDECLARE @strOutput VARCHAR(200) SET @strOutput = '' SELECT @strOutput = @strOutput + '/' + [boxes] FROM flexing_stock_transactions WHERE [item] = @item AND [price] = @price ORDER BY boxes DESC RETURN STUFF(@strOutput, 1, 1, '') ENDbut I get the error: Msg 8120, Level 16, State 1, Line 1Column 'flexing_stock_transactions.item' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.Msg 8120, Level 16, State 1, Line 1Column 'flexing_stock_transactions.price' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.Where am I going wrong please?Newbies eh? :) |
 |
|
|
|
|
|
|
|