var sidebar_align = 'right';
var content_container_margin = parseInt('290px');
var sidebar_width = parseInt('270px');
Unanswered: sql statement for records summary
suppose the recordset like this, that shows the cell phone models of nokia, siemens,...
now, i want to organize these records to somethin like this:
IDModel Mark ModelCaption
1 nokia 6100
2 nokia 6220
3 nokia 6600
4 siemens mc65
5 siemens sx1
how can i do it?
Create function MarkModels(@Mark integer)
Returns varchar(500) as
Declare @ModelString varchar(500)
set @ModelString = ''
Select @ModelString = @ModelString + ModelCaption + ', ' from YourTable where Mark = @Mark
return left(@ModelString, len(@ModelString) - 1)
Sorry if the syntax is off, but hopefully you'll see the method being used. You will have to include this function in the result set of your query, and the process may be slow if your table is large.
i posted this thread years ago, anyone can write a view for this?
This technique will not work as a view. Only as a function.
Now, you could write a view that calls the function...
Please find the query and the function
The below code is the function
CREATE FUNCTION [dbo].[fn_getmodelcaptions] (@mark varchar(100))
RETURNS varchar(500) AS
declare @modelcaptions varchar(500)
select @modelcaptions = coalesce(modelcaption+','+@modelcaptions,modelcapt ion) from yourtable where mark = @mark
please find the query to get the desired result
select mark,dbo.fn_getmodelcaptions(mark) from yourtable group by mark
Did you have a specific question?
No I am replying to bono's question
Kinda late, since that thread had been dormant for nearly two months...