sql server - Processing a resultset to look up foreign keys (and poulate a new table!) -


I have been given a dataset with some key basic tabular structures. Such as

  {myRubishTable} - area (varchar), AuthorityName (varchar), StartYear (varchar), StartMonth (varcha), EndYear (varchar), EndMonth (varchar), zodiac (money) < / Code> 

There are other tables that use the area and authorization name, as well as months and years of normal use, so the second one is a good first step to authorize the authorization and authorization in your area. The tables were planted to pull in.

Now I want to process the data in the original table and I want to see the key value to keep my new table in foreign keys that look like this.

  (see table) {area} - id (int, pk), name (varchar (50)) {authorityName} - id (int, pk), name (varchar (50) ( TargetTable) {myBetterTable} - ID (integer, P), area_id (int FK-area), authority_name_id (int FK-AuthorityName), StartYear (varchar), StartMonth (varchar), EndYear (varchar), EndMonth (varchar), amount (Money)  

Row one in the old table

  Merry, Mythory, 2009, January, 2010, February, 10000  

and I want to populate a new table with

  1,1,1,2009, January, 2010, February, 10000  

Where the first '1' primary key And there are IDs in the lookup tables of the second two.

Can someone tell me the most effective way of getting it using SQL?

Footnotes: - I have achieved what I needed to leave with a very tablename in some very simple section (where I was thrown from: (o) but if it is most interested to know would be skilled .

i.e.

  SELECT [area]. [Area_id], [rights]. [Authority_name_id], [myRubishTable]. [StartYear], [myRubishTable] [StartMonth], [myRubishTable] [EndYear], [myRubishTable] [EndMonth], [myRubishTable] [Zodiac] [myRubishTable], from [region], [AuthorityName] where [myRubishTable] [Region] = [area]. [Name] and [myRubishTable]. [Authorization name] = [dim_AuthorityName]. [Name]   

after your footnote

  First, second, jade is equal to Xa = yes and Xb = Zb  

but with more idiomatic SQL

  Join X from within Xa = yes inner-jaded Zed on Zedb = ZB  

I do not think there is enough to add. For some who will be run only once (right?), Efficiency should not really be your main concern - should be correct. Unless you have so data or such is an incompetent method, which actually takes too long, absolutely ...


Comments