Solved

How to reference two data sources in SQL Reporting Servcies

Posted on 2009-07-09
4
200 Views
Last Modified: 2012-05-07
Hi there,

I want to create a report in SQL Reporting where my query references two shared datasources in the report.

I have created the shared data sources and individually they are working fine. lets call them Data1 and Data2.

 What I want to do is something like this

Select CompanyName (Data1), Address(Data1), ContractType(Data2)

where companyID(Data1) = companyID(Data2)

the reason I need this is that some info is in data2 that is not in data1 but I need to create a report that lists it all in one table.

I am not sure if I create two shared DB Datasources if I can reference them from within the same table or do i have to create a linkserver connection from within my query.

If anybody has sample code too that would be really helpful.

Also does anybody know of any good resources for advanced SQL Reporting.

Cheers

Michael
0
Comment
Question by:mickinoz2005
  • 2
4 Comments
 
LVL 13

Expert Comment

by:St3veMax
ID: 24813498
If CompanyID is unique, Create a stored procedure in SQL that returns all data you need, then with your two datasets, have one which returns all customer names and ID's and use that as a parameter to pass into your 2nd dataset which executes the stored proc, but passes in the CustomerID.

HTH
0
 
LVL 8

Expert Comment

by:Hadush
ID: 24814175
One dataset can only refere one database at a time. I think the only way if you want to join data from the datasources you can write in the query  and give it full name when you call the tables. If they are both in one server you can use something like the following code. If they are different servers, you need to use like open query.
 

--You can point to any of the shared databases and will figure out by itself the second database.

Select 

t1.CompanyName 

, t1.Address

, t2.ContractType

FROM Database1.dbo.Table1 t1  

Left join Database2.dbo.Table2 t2  --which ever join works for you

ON t1.CompanyID=t2.CompanyID

Open in new window

0
 
LVL 5

Author Comment

by:mickinoz2005
ID: 24814316
Hiya,

Sorry a little confused on response -

The two DB are on different servers. So if i create two shared DB sources i cannot use them in the query.

So lets say the query I want is something like this

Select D1.CompanyID, D2.Groupname
From data1.company as D1,data2.compgroup as D2
Where data1.company.companyID = data2.compgroup.companyID

How would I write this in the query using the correct syntax to get it to work..

Cheers for your help

Michael


0
 
LVL 5

Accepted Solution

by:
mickinoz2005 earned 0 total points
ID: 24905282
I resolved this myself.

We just created a linked server in our SQL and then just referenced the linked server from within our query.

Thanks

Michael
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

937 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now