Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

Help in Creating a view with multiple databases in sql server 2008

$
0
0

Friends,

I need a view by using the below four separate queries. is it possible with these different kind of where condition?

from hostel database i will be getting hostel fees and from the three colleges database i will be getting the tuition fees of their respective colleges.

i need it like below

rollnumber, firstname, initial, hostelfees, tuitionfees, yearcourse,college

use hostel

select sc.RollNumber,s.FirstName,s.Initial,sc.Balance as 'HostelFees','' as

TuitionFees,b.YearCourse,s.College
from Student_Closing sc,Student s,batchcourse b
where
s.RollNumber =sc.RollNumber
and
b.BatchCode =s.Batch
and
sc.Balance > 5000
and
b.FeeActive ='Y'
order by s.College,sc.RollNumber



use college1

select sc.RollNumber,s.FirstName,s.Initial ,'' as HostelFees,sc.Balance as

'TutionFees',b.YearCourse,'college1' as College
from Student_Closing sc,Student s,batchcourse b,Applicant a
where
s.RollNumber =sc.RollNumber
and
b.BatchCode =s.Batch
and
b.FeeActive ='Y'
and
s.ApplNo =a.ApplNumber
and
a.Community not in ('S','T','A','P')
and
((sc.Balance > 0 and a.GraduateType not in ('F'))
or
(a.GraduateType='F' and sc.Balance > 20000))
and
s.FeeActive ='Y'
and
s.RollNumber not like '15%'
order by
sc.RollNumber


use college2

select sc.RollNumber,s.FirstName,s.Initial ,'' as HostelFees,sc.Balance as

'TuitionFees',b.YearCourse,'college2' as College
from Student_Closing sc,Student s,batchcourse b
where
s.RollNumber =sc.RollNumber
and
b.BatchCode =s.Batch
and
b.FeeActive ='Y'
and
sc.Balance > 0
order by
sc.RollNumber


use college3

select sc.RollNumber,s.FirstName,s.Initial ,'' as HostelFees,sc.Balance as

'TutionFees',b.YearCourse,'college3' as College
from Student_Closing sc,Student s,batchcourse b,Applicant a
where
s.RollNumber =sc.RollNumber
and
b.BatchCode =s.Batch
and
b.FeeActive ='Y'
and
s.ApplNo =a.ApplNumber
and
a.Community not in ('S','T','A','P')
and
((sc.Balance > 0 and a.GraduateType not in ('F'))
or
(a.GraduateType='F' and sc.Balance > 20000))
and
s.FeeActive ='Y'
and
s.RollNumber not like '15%'
order by
sc.RollNumber


thanks


Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>