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 |
|
jdaly
Starting Member
1 Post |
Posted - 2006-07-11 : 11:03:00
|
| I created a report based off of two views so that I could pull data regarding the leads and the notes regarding those leads, below is the SQL statement I use to do thisSELECT dbo.FilteredLead.companyname, dbo.FilteredLead.new_productname, dbo.FilteredLead.new_clientbusinesstypename, dbo.FilteredLead.subject, dbo.FilteredAnnotation.notetext, dbo.FilteredLead.fullname, dbo.FilteredLead.description, dbo.FilteredLead.leadsourcecodename, dbo.FilteredLead.owneridnameFROM dbo.FilteredAnnotation INNER JOINdbo.FilteredLead ON dbo.FilteredAnnotation.objectid = dbo.FilteredLead.leadidWHERE (dbo.FilteredLead.leadsourcecodename = 'Quote & Bound Report')ORDER BY dbo.FilteredLead.companynameNow this statement works out pretty well and returns the data that I want with one small problem. If a lead has more than one note associated with it the results will have the company listed twice. Looking something like belowCompanyname1 Note ACompanyname2 Note ACompanyname2 Note BCompanyname2 Note CCompanyname3 Note ACompanyname3 Note BThis isnt too huge of a deal but I would liek to have it so each company only has one heading with all the notes listed under it, like. Companyname1 Note ACompanyname2 Note A Note B Note CCompanyname3 Note A Note BAny ideas or help is appreciated. |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-07-11 : 11:11:08
|
Can you handle this in the front end application ? SQL Server is not meant to perform this type of data formatting. KH |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2006-07-11 : 11:11:57
|
| Can you not do this in whatever you are using for the report?==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
RyanRandall
Master Smack Fu Yak Hacker
1074 Posts |
Posted - 2006-07-11 : 12:34:05
|
| +1 for doing this in the front-end.Ryan Randallwww.monsoonmalabar.com London-based IT consultancy Solutions are easy. Understanding the problem, now, that's the hard part. |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2006-07-11 : 13:24:24
|
| Oh wellset nocount onSELECT dbo.FilteredLead.companyname, dbo.FilteredLead.new_productname, dbo.FilteredLead.new_clientbusinesstypename, dbo.FilteredLead.subject, dbo.FilteredAnnotation.notetext, dbo.FilteredLead.fullname, dbo.FilteredLead.description, dbo.FilteredLead.leadsourcecodename, dbo.FilteredLead.owneridname ,identity(int,1,1) as idinto #aFROM dbo.FilteredAnnotation INNER JOINdbo.FilteredLead ON dbo.FilteredAnnotation.objectid = dbo.FilteredLead.leadidWHERE (dbo.FilteredLead.leadsourcecodename = 'Quote & Bound Report')select case when id = (select min(id) from #a a2 where a2.companyname = a.companyname) then companyname else '' end, , new_productname, new_clientbusinesstypename, ......from #a aORDER BY dbo.FilteredLead.companyname, id==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|
|
|