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 |
Tuan
Starting Member
2 Posts |
Posted - 2014-09-26 : 06:15:23
|
Hi,I am new to SQL server and I've been tasked to transfer some data from Excel to SQL, with some logics to be performed in SQL. One issue that I haven't been able to solve is to use a vlookup-like function in SQL.I have a fact table and a dimension table. Format is shown as follows.Fact table:ID Name Desc Region1 a xxxx UK2 b yyyy US3 c zzzz US4 d aaaa ChinaDimension table:Region_ID Region_Name1 US2 UK3 China4 JapanWhat I'd like to achieve is to do a look-up check and replace the regions in the fact table with region IDs, according to the dimension table. Can someone please help me out on this? Thanks in advance.Regards,Tuan |
|
djj55
Constraint Violating Yak Guru
352 Posts |
Posted - 2014-09-26 : 07:16:48
|
In T-SQL you use a JOIN. To replace you use an UPDATE. Something like:UPDATE FSET Region = D.Region_IDFROM Fact FINNER JOIN Dimension D ON F.Region = D.Region_Name djj |
|
|
Tuan
Starting Member
2 Posts |
Posted - 2014-09-26 : 07:40:37
|
Thanks a lot djj! Works perfectly now. |
|
|
|
|
|