Hey there,
Im wondering if there is a way to determine which views in my database use the "order by" statement.
The reason I need this is because we need to migrate over to MS SQL 2005 where the order by statements are ignored within the views themselves. Now(in mssql 2005) you need to explicityly state the order by now when calling a view
ie. select * from [viewname] order by column x, y desc, z
instead of
ie. select * from [viewname]
where the view already had the applicable sorting done within the view.
If those order by statements are ignored, some production software which rely on the ordered data will corrupt.
Please let me know if there's a way to query the actual database and determine which views have 'order by' statements in them.
thxi dont think you can have order by clause in VIEW.|||you can in MS SQL 2000 but not in MS SQL 2005|||My SQL2K did complain order by in view, it seems strange. Anyway you can try to search for "order by" in syscomments if your views are not encrypted.|||you can use this script to list the view names having order by clause
select name from dbo.sysobjects where objectproperty(id, N'IsView') = 1 and
id in (select id from dbo.syscomments where text like '%order by%')|||you can use this script to list the view names having order by clauseYou need to put a BIG caveat on this idea... While it works for views with nicely formatted source code, it can generate both false positives (for any view with either a commented ORDER BY clause, or the text ORDER BY), and false negatives (where the words order and by have something other than a space between them, such as a line-end, tab, multiple spaces, comments, etc).
The only way to be truly certain is to actually parse the view and check the tokenized output for an ORDER BY. This is beyond the reach of simple Transact-SQL, although I'm thinking about a couple of ways that could let you work around this limitation.
-PatP|||Thx for all the responses. I will try the following:
select name from dbo.sysobjects where objectproperty(id, N'IsView') = 1 and
id in (select id from dbo.syscomments where text like '%order by%')
as suggested by kadapa22. Although it may result in both false postives and negatives, I think it's worth a try. Better than manually looking through over 800 views manually. I will let you know how it goes.
thx again.|||Thx for all your advice. I decided to take a different approach to make sure I get the proper results. I exported all my views to a text file and will search through that instead.
thx again for all your help.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment