Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

sql server - SQL data returned in a comma-delimited list -


here tables:

----------------------------------------- hotels ----------------------------------------- hotelid | hotelname -----------------------------------------   ----------------------------------------- hotelimages ----------------------------------------- hotelimageid | hotelid | filename ----------------------------------------- 

i'd create select statement return data so:

hotelid | hotelname | images ----------------------------------------- 1 | hotel1 | image1,image2,image3 2 | hotel2 | image4,image5,image6 

how can modify query this? have:

select h.hotelid, h.hotelname, '' images hotels h 

i know can use coalesce create comma-delimited list:

declare @images varchar(500) select @images = coalesce(@images + ',', '') + cast(filename varchar(100)) hotelimages hotelid = 1 select @images 

but don't know how integrate current query list can returned rest of hotel data.

i should mention i'm using sql server 2000.

since sql 2000 options limited. can't use xml path or recursive ctes

also coalesce trick works stuffing comma delimited list single hotel. not of them.

honestly you're better off doing in client. if can't done (certain report apps that-which-must-not-be-named come mind) can following.

note number of times loop process equal maximum number of files associated hotel. better setting loop each hotel (e.g. calling udf select clause).

declare @foo table ( hotelid int , lastid int , filenamelist varchar(8000))  insert @foo   select     start.hotelid,     start.firstid ,     id.filename       (select          hotelid,         min(hotelimageid ) firstid              hotelimages       group hotelid) start     inner join hotelimages hi     on start.firstid = hi.hotelimageid    while @@rowcount <> 0  begin      update @foo     set          filenamelist = filenamelist + ',' + filename         lastid  = xnext.nextid              @foo f         inner join hotelimages hi         on f.hotelid = id.hotelid         inner join          (select               id.hotelid,             min(hotelimageid ) nextid         hotelimages hi               inner join @foo f               on f.hotelid = id.hotelid         id.hotelimageid  > f.lastid           group id.hotelid) xnext          on xnext.nextid = id.hotelimageid     end   select      h.hotelid      h.hotelname,     f.filenamelist     hotels h     inner join @foo f     on h.hotelid = f.hotelid 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -