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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 we need hint for function creation

Author  Topic 

ramu143
Yak Posting Veteran

64 Posts

Posted - 2008-07-21 : 07:09:28
we have three quiries . in each quiery we are taking the data from different databases and same table please write a function to add the(link the three databases)

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-07-21 : 07:12:34
Use UNION keyword

SELECT * FROM Source1
UNION ALL
SELECT * FROM Source2
UNION ALL
SELECT * FROM Source3



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-07-21 : 08:55:09
Also note that number of columns and their datatypes in each query should be identical

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-21 : 10:14:30
quote:
Originally posted by ramu143

we have three quiries . in each quiery we are taking the data from different databases and same table please write a function to add the(link the three databases)


you want the data from each query to be appearing as rows or do you want to join the fields from them into a single result set?if former, use UNION ALL. and if later use like below
SELECT q1.fields,q2.fields,q3.fields
FROM
(
SELECT * FROM Source1)q1
INNER JOIN
(
SELECT * FROM Source2)q2
ON q2.commonfields=q1.commonfield
INNER JOIN
(
SELECT * FROM Source3)q3
ON q3.commonfields={q1/q2}.commonfield
Go to Top of Page
   

- Advertisement -