sql server 2008 - Update Across Tables -
i need set values in database , can't work. (i'm using ssms 2008 r2)
the tables involved dbo.scales
, dbo.posscore
.
dbo.scales
contains 4 columns:
grade (varchar)
upper bound (int)
lower bound (int)
award (varchar)
dbo.posscore
has 2 columns:
possible score (int)
grade (varchar)
i need fill dbo.posscore
table appropriate grade according bounds given in dbo.scales
table.
it best if referential i.e. if change boundaries table adjusts accordingly.
how should go this?
you have 2 options if want values in posscore
change when alter values in scales
: either create trigger on scales
(re-)creates posscore
table whenever needed (or updates it), or use view changes dynamically. unless amount of data needs change prohibitively large , recalculating posscore
values takes long view should best option.
one way create view use suitable table number range covers upper , lower bounds. fortunately sql server has system table can used purpose (provided range falls in span 0-2047.
a query create view below:
create view posscore select s.grade, number "possible score" master..spt_values v join scales s on v.number <= s.upperbound , v.number >= s.lowerbound , v.type = 'p'
Comments
Post a Comment