August 23, 2005 at 10:59 am
SELECT *
into #v_saleproperty
FROM OPENQUERY(Server1, 'Select city, MLS_nbr from California.dbo.v_HomeSales')
SELECT city
from #v_saleproperty
WHERE EXISTS (select *
from v_homes
WHERE home_id = #v_saleproperty.MLS_nbr)
After running these queries, I want to add a city column to the view v_homes with #v_saleproperty.city data. What is the next query I write?
Thanks for feedback.
August 23, 2005 at 11:23 am
You're working backwards... do the work from the other server, everything will be easier that way.
August 23, 2005 at 11:43 am
thanks for the reply. the view I am altering is on server 2 though.
August 23, 2005 at 11:46 am
Can you expand a bit more on the task at hand??
August 23, 2005 at 11:55 am
On server2 I have a view v_homes that I need to add a city column which is populated from server1.v_HomeSales.city. hope that makes sense.
August 23, 2005 at 11:57 am
No because a view is not a table, you can add a column to a table but you only add a column in the select of the view (view definition).
Are you talking about indexed views that would need access on some remote server data??
August 23, 2005 at 12:05 pm
okay sorry. left out that step. after i alter the table to add the city column with the data from server1, i would then alter the view by selecting from the table.
so I guess my question is how do I add the city column with the data from server1 to the table homes?
August 23, 2005 at 12:25 pm
Do they contain the same data?
Can I see some sample data of matching rows and the ddl?
August 23, 2005 at 12:50 pm
I have inserted my recent comments in green below.
Thanks so much for your help! (and patience
)
SELECT *
into #v_saleproperty
FROM OPENQUERY(Server1, 'Select city, MLS_nbr from California.dbo.v_HomeSales')
SELECT city
from #v_saleproperty
WHERE EXISTS(select * from Server2.California.dbo.dim_homes
WHERE home_id = #v_saleproperty.MLS_nbr)
/*getting only the #v_saleproperty.mls_nbrs that match in dim_homes.home_id.
the above Select statement returns 1966 rows
#v_saleproperty.mls_nbrs contains 4765 records
dim_homes contains 1968 records
*/
/* This is where the next query would go to alter the table dim_homes to add the city column data . I am not sure how to do this part.
/*This last query would be to alter the view to reflect the change to the table dim_home.*/
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
ALTER view v_dim_homes
as
SELECT * FROM dim_homes
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
August 23, 2005 at 1:35 pm
How do you intend to keep the table syncronized over time??
August 23, 2005 at 1:51 pm
Probably a sceduled dts job.
August 23, 2005 at 1:56 pm
Hmm, I think you should look into replication for this )obviously not the only way, but that's the way I'd look into as it's all automatic).
August 23, 2005 at 2:00 pm
Probably a scheduled DTS job.
August 23, 2005 at 2:02 pm
oops didn't mean to post my reply twice.
Remi, thanks for all help and posts.
August 23, 2005 at 2:04 pm
HTH.
Viewing 15 posts - 1 through 15 (of 15 total)
You must be logged in to reply to this topic. Login to reply