July 22, 2013 at 9:16 am
Have a strange request from the apps folks. Here is what they want:
We have three SQL Server databases with the same table and columns but the data within the tables belongs to different company/entities. They are going to pull out that data and put it into an Oracle database but once they get it into the Oracle database there is no way to know which rows came from which database. So, they want to create a view on these specific tables and have a self populating column in the view that has the database name in it. Then the Oracle DB will have the name DB_Origin and will then be populated with that name so they will be able to tell which SQL Server DB that data came from. How would I construct that view?
As an Example this is what the table looks like in Database Name WEN01:
Date
Item
Sales
View would be:
Date
Item
Sales
WEN01 hardcoded
July 22, 2013 at 9:20 am
Like this?
select Date, Item, Sales, 'WEN01' as SomeColumn
from SomeTable
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
July 22, 2013 at 9:31 am
or this?
select Date, Item, Sales, db_NAME() as SomeColumn
from SomeTable
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
July 22, 2013 at 9:51 am
Jeesh... thanks gang..... it is simple... I was just thinking too hard about it. Got it.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply