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 |
|
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 keywordSELECT * FROM Source1UNION ALLSELECT * FROM Source2UNION ALLSELECT * FROM Source3 E 12°55'05.25"N 56°04'39.16" |
 |
|
|
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 identicalMadhivananFailing to plan is Planning to fail |
 |
|
|
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 belowSELECT q1.fields,q2.fields,q3.fieldsFROM(SELECT * FROM Source1)q1INNER JOIN(SELECT * FROM Source2)q2ON q2.commonfields=q1.commonfieldINNER JOIN(SELECT * FROM Source3)q3ON q3.commonfields={q1/q2}.commonfield |
 |
|
|
|
|
|