January 11, 2004 at 2:09 am
i can create a view from another view for example :
create view viewX
as
select o.Locationid,o.Itemcode,o.openingdate,o.openingQty
from view1 as o
………..
left join view2 as MR on o.Locationid=MR.Locationid
left join view3 as TR on o.Locationid=TR.Locationid
left join view4 as TI on o.Locationid=TI.Locationid …….
where .......
so if i use here store procedure, how can i do this as above?
..Better Than Before...
January 11, 2004 at 1:34 pm
DECLARE @stmt NCHAR(1000)
SET @stmt = 'CREATE VIEW....'
EXEC (@stmt)
If you want this on a regular basis, you might want to take a look at sp_executesql in BOL. It has some advantages over the simple exec.
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
January 12, 2004 at 2:32 am
You may consider using table valued function instead of a stored procedure.
If You need to join on the result returned from the sp.
/rockmoose
You must unlearn what You have learnt
January 12, 2004 at 3:29 am
What abot the "table valued function" ?
can u clear it little bit?
..Better Than Before...
January 12, 2004 at 3:30 am
What about the "table valued function" ?
can u clear it little bit?
..Better Than Before...
January 12, 2004 at 3:39 am
I think rockmoose means a user-defined function that returns a table. From BOL
CREATE FUNCTION LargeOrderShippers ( @FreightParm money )
RETURNS @OrderShipperTab TABLE
(
ShipperID int,
ShipperName nvarchar(80),
OrderID int,
ShippedDate datetime,
Freight money
)
AS
BEGIN
INSERT @OrderShipperTab
SELECT S.ShipperID, S.CompanyName,
O.OrderID, O.ShippedDate, O.Freight
FROM Shippers AS S INNER JOIN Orders AS O
ON S.ShipperID = O.ShipVia
WHERE O.Freight > @FreightParm
RETURN
END
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
January 12, 2004 at 4:15 am
Yes, that was what I meant.
/rockmoose
Franks example could be written ( more lazily, if you don't want to spec the table  as:
CREATE FUNCTION LargeOrderShippers ( @FreightParm money )
RETURNS TABLE
AS
RETURN
SELECT
S.ShipperID,
S.CompanyName,
O.OrderID,
O.ShippedDate,
O.Freight
FROM
Shippers AS S INNER JOIN Orders AS O
ON S.ShipperID = O.ShipVia
WHERE
O.Freight > @FreightParm
Observe: different query plans are made by SQL Server for the 2 examples, I am not sure if performance is an issue here.
/rockmoose
You must unlearn what You have learnt
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply