Solved

SQL Server Report Custom Code - Use Datasource

Posted on 2011-03-07
8
871 Views
Last Modified: 2012-05-11
Is it possible to use the datasource of an ssrs report inside of the custom code section.  I want to utilize the same connection as the report to return other data from the same connection, but a different query.

Ex:
Report datasource name = ds
function test() as string
     test = ds.connectionstring
end function
0
Comment
Question by:pmeharry
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 10

Expert Comment

by:itcouple
ID: 35055965
Hi

Code cannot talk to neither data sources nor data sets.

What are you actually trying to achieve?

Regards
Emil
0
 

Author Comment

by:pmeharry
ID: 35056238
Due to reasons outside my control I cannot create temp tables or temp functions.  I want to write a query like:

select apptid, time, place, whoid

where there may be several whoid's.

so I would normally write

select apptid, time, place, getwho(apptid)
which would return something like

1001 , "3/7/2011 11:53 am", "city", "sally, bob, john"

By capturing the datasource / connection string I want to create a VB function that will look up the who's.
0
 
LVL 10

Expert Comment

by:itcouple
ID: 35056762
Hi

Not sure if I understand... when you say look up who's. What exactly would you do?

Are you using 2008 or 2008 R2?

I'm getting an impression that you might have other options but I need to understand the look up bit.

Regards
Emil
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:pmeharry
ID: 35056843
CREATE FUNCTION #GetWho(@apptid int)
  RETURNS VarChar(300)
AS
BEGIN
      DECLARE @Names varchar(1000)
      DECLARE @Name  varchar(400)

      DECLARE c CURSOR for
            select name
                                                     from table t
                                                     where t.id = @apptid
      OPEN c
      Fetch Next FROM c into @Name
      While @@FETCH_STATUS = 0
      Begin
            If @Names is null
                  set @Names = @Name
            else
                  set @Names = @Names & ', ' & @Name
      End

      Close c
      Deallocate c
      
      set @Names = substring(@names, 1, 300)

    RETURN @Names
END
0
 

Author Comment

by:pmeharry
ID: 35056860
Forgot my context.  This is a TSQL function.  The VB Code would
have to make a connection using the connnection from the report first.

THen implement a function somewhat similar to this one.
0
 
LVL 10

Assisted Solution

by:itcouple
itcouple earned 500 total points
ID: 35057030
I see your problem. I don't have definitive answer apart from that the answer to your original question is no, you cannot do that.

My approach would be to join tables (ID to get name) which will result in multiple rows (with different name). then use code to combine them (comma separate values). So you should be able to replicate what you did in a function. I'm don't use SSRS code in this way as I don't have sql server restrictions :). I suggest posting this specific question I'm sure there are some experts who use SSRS Code this way.

Hope that helps
Emil

0
 

Accepted Solution

by:
pmeharry earned 0 total points
ID: 35057137
Thanks for your time & help!
0
 

Author Closing Comment

by:pmeharry
ID: 35120642
Basically there is not solution.
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Getting local user timezone in Sql Server 5 40
grouping by date only 6 22
Help with SQL pivot 11 49
Visual Studio 2015 Report Viewer has blank data source? 1 15
Introduction In the following article I’ll be discussing and demonstrating several different ways of how images can be put on a report. I’m using SQL Server Reporting Services 2008 R2 CTP, more precisely version 10.50.1352.12, but the methods ex…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question