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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 CTE inline versus stored procedure, performance?

Author  Topic 

sql777
Constraint Violating Yak Guru

314 Posts

Posted - 2007-12-25 : 16:24:24
Hi,

While I like stored procedures, an application I have to build requires alot of variations for my queries.

For example, I might want to ORDER BY things like userID, dateCreated, contentID, etc. Making stored procedures with CTE's and have all the various ORDER BY variations makes things difficult!

***So my question, is there any performance issues with putting a CTE inline versus a sproc?

example:

WITH myCTE(column1, column2, column3)
AS
(
SELECT f1, f2, f3
FROM Table1
WHERE f1 = @f1

UNION ALL

SELECT t.f1, t.f2, t.f3
FROM Table1 t
INNER JOIN myCTE m ON (t.f1 = m.f3)
)

SELECT *
FROM myCTE

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-12-26 : 12:05:13
Can you post the two execution plans so we can compare them?



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

sql777
Constraint Violating Yak Guru

314 Posts

Posted - 2007-12-26 : 20:19:09
Wouldn't they be the same? The query is the exact same, just one is via a stored procedure and the other is writtin inline in asp.net (using parametrized queries)
Go to Top of Page
   

- Advertisement -