Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 15th, 2004, 04:44 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

It is true that views do not allow parameters, but why do you think you need parameters on the view? A view is nothing more than a 'virtual' table, materialized when it is referred to. You don't have parameters on a table so you don't have them on views either. Instead, you have parameters on the queries which manipulate those tables.

Any parameters would be used to restrict the rows returned from the query which uses the view. For example:
Code:
SELECT col1,col2, ...
FROM yourtable
    INNER JOIN yourview
        ON yourtable.somecolumn=yourview.someothercolumn
WHERE yourtable.onecolumn=@FirstParameter
  AND yourview.anothercolumn=@SecondParameter
...etc
I doubt you'll need temp tables, since the view essentially serves that purpose and is a *lot* faster.

T-SQL isn't SQL either.

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
 
Old March 25th, 2004, 07:15 AM
Authorized User
 
Join Date: Jun 2003
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Default

 
Quote:
quote:Both HAVING and WHERE are similar, but the WHERE clause selects rows before the grouping operation, and the HAVING clause selects rows (groups actually) after the grouping operation. Since generally speaking a grouping operation is a resource intensive operation, if you can reduce the number of rows going in, the query will have less rows to group which should mean it will run faster.
Quote:
Jeff. I am reading a book by Ken Henderson. He agrees with you that the correct way to select rows is via the WHERE clause. But, he claims that if you do use the HAVING clause to select rows, SQL Server will internally translate the HAVING clause to a WHERE clause, so the performance should be the same. Just thought I would throw this into the discussion :)

Gert

 
Old March 25th, 2004, 07:42 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

Would that be "The Guru's Guide to Transact-SQL"?

Very good book, IMO.

I see that he does say, quoting on P19, where he presents an example of a selection that should be done via a WHERE clause but instead is done in a HAVING clause:
Quote:
quote:
... SQL Server recognizes this type of HAVING misuse and translates HAVING into WHERE during query execution. Regardless of whether SQL Server catches errors like these, it's always better to write optimal code in the first place.
Note that Ken characterizes misplaced row selection in a HAVING clause as "misuse" and an "error". For what it is worth, I'd be leery of depending on my tool to cover my mistakes. I doubt there would be any guarantee that this kind of behavior would be supported forever in future versions of SQL Server, nor would there be any in any other product, should porting ever be an issue.

Do it right the first time. :)





Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
 
Old March 25th, 2004, 08:46 AM
Authorized User
 
Join Date: Jun 2003
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The book was "The Guru's Guide to SQL Server Stored Procedures..."

I totally agree with both you and mr Henderson. Just thought I should mention it..

Gert






Similar Threads
Thread Thread Starter Forum Replies Last Post
replace function for line breaks crazeydazey XSLT 6 September 1st, 2008 03:53 AM
mail() function and From line allgoodnamesaregone Beginning PHP 1 January 19th, 2006 09:04 AM
GETDATE? drachx SQL Server 2000 2 February 17th, 2005 08:05 AM
retreive function/Line from macro or function? MikoMax J2EE 0 April 1st, 2004 04:42 AM
GETDATE() dose not......... arshad mahmood SQL Server 2000 2 August 19th, 2003 07:57 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.