Showing posts with label exists. Show all posts
Showing posts with label exists. Show all posts

Sunday, March 25, 2012

create a script to display all the rows of the view

I have a view that has a link to 3 tables.
I need to display all the rows of the view.
here is the code for the view.
USE Aromatherapy
GO
if exists (select name from sysobjects
where name = 'Oils_Cautions_View' and type
= 'V')
DROP VIEW
Oils_Cautions_View
go
CREATE VIEW Oils_Cautions_View AS
SELECT o.oilID, oilName,
Description FROM Oils AS o, Cautions as c, OilCautions as
oc
Where o.OILID = oc.OilID AND c.CautionID = oc.cautionID
I like to thank you ahead for the help
Thank you
Cristianselect * from Oils_Cautions_View
"Cristian" <vitanc@.hotmail.com> wrote in message
news:0c9901c392a4$2903c2b0$a001280a@.phx.gbl...
> I have a view that has a link to 3 tables.
> I need to display all the rows of the view.
> here is the code for the view.
> USE Aromatherapy
> GO
> if exists (select name from sysobjects
> where name = 'Oils_Cautions_View' and type
> = 'V')
> DROP VIEW
> Oils_Cautions_View
> go
> CREATE VIEW Oils_Cautions_View AS
> SELECT o.oilID, oilName,
> Description FROM Oils AS o, Cautions as c, OilCautions as
> oc
> Where o.OILID = oc.OilID AND c.CautionID = oc.cautionID
> I like to thank you ahead for the help
> Thank you
> Cristian
>|||1. Create DB Links OLE DB SQL Links for all the 3 servers.
say:
DBLINK1 points to Server1.employee
DBLINK2 points to Server2.employee
DBLINK3 points to Server3.employee
create view v_employee as
select * from dblink1...employee
union
select * from dblink2...employee
union
select * from dblink3...employee
go
select * from v_employee
There is no need for 'Hardcoding' the db servername.
If server needs to changed, you change it at the Link creation time.

Tuesday, March 20, 2012

Create a cube- only of linked objects ?

How do you create a new cube, that only exists of linked objects. As i see it, you can only create a cube by selecting source, fact table etc. - and then afterwards add linked objects to the cube....

Hmm seems like the easiest way is to create a cube, is to select at fact and dimension - finish and the delete those again. Then you have e "blank" cube and can add the linked objects....

Create (U)SP in database on linked server

Hi,
I'm using a couple of linked servers.
I want to create a stored procedure on all of the linked servers in a database with a name which exists on all of the linked servers.
For executing SQL on all of the linked servers I'm using:

declare @.x int
declare @.dbname varchar(500)
declare @.SQL nvarchar(600)
set @.x = 1
create table #databases (ID int IDENTITY,name varchar(500))
insert #databases select instancelongname from instances
while @.x <= (select max(id) from #databases)
begin
select @.dbname = name from #databases where id = @.x
select @.SQL='blabla bla bla create PROCEDURE [dbo].[usp_xxxx]'
execute @.SQL
set @.x = @.x + 1
end
drop table #databases

Is it possible to use a create procedure in this construction?
Can anybody give me some help how to create a proper syntax for it?

Any help is kindly appreciated!Your code assumes that the database IDs are sequential and continuous, which they are probably not, so you are going to generate a lot of errors with this. But as far as creating the sprocs, your dynamic SQL will need to start with a USE statement to set the scope to your target database.