What is the difference between SET and SELECT?

Tuesday Feb 17th 2004 by DatabaseJournal.com Staff

Both SET and SELECT can be used to assign values to variables. But when to use or not use SET or SELECT? Or does it matter? This articles shows you how SET and SELECT are different in various scenarios, along with examples. You will also find a test script that you can run, to identify the performance differences between SET and SELECT.

[From Narayana Vyas Kondreddi]

What is the difference between SET and SELECT when assigning values to variables, in T-SQL?

Traditionally, SQL Server database developers are accustomed to using SELECT for assigning values to variables. This was fine and a perfectly valid practice right until SQL Server 6.5. Microsoft released SQL Server 7.0 in 1999. SQL Server 7.0 introduced the new SET statement for initializing and assigning values to variables. SQL Server 7.0 Books Online also stated: "It is recommended that SET @local_variable be used for variable assignment rather than SELECT @local_variable."

This caused some confusion in the database developer community, as Microsoft never mentioned, why SET is recommended over SELECT for assigning values to variables. In this article, I will highlight all the major differences between SET and SELECT, and things you should be aware of, when using either SET or SELECT.

The article continues at http://vyaskn.tripod.com/differences_between_set_and_select.htm

Mobile Site | Full Site
Copyright 2017 © QuinStreet Inc. All Rights Reserved