What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 19176 |  Welcome, Guest!   Register  Login
 Home > Blogs > SQL Server > SET or SELECT -- is there any performance difference? ...
Jvprabhusanthi

SET or SELECT -- is there any performance difference?

 Blog author: Jvprabhusanthi | Posted on: 5/15/2012 | Category: SQL Server Blogs | Views: 484 | Status: [Member] | Points: 75 | Alert Moderator   


It doesn't have a major performance difference between the Set and Select statement. The only thing is the usability nature of the commands.

 

            SET @variable = (SELECT datacolumn FROM tablename)

The above statement should return a single value which will be assigned to the variable. Here, if the results of the subquery expression is empty then @variable has a value of NULL but if the results of the subquery are more than one row then you get a error.

And thus it makes sense while,

 

SELECT @variable = columnvalue FROM dbo.tablename

 

returns a value from a number of rows and we are not sure what's the criteria in selecting that row.

 

 One major difference in assigning using SET and SELECT is:

 

SET @variable1 = 'somevalue', @variable2 = 'someothervalue'

 

This is NOT possible but the same is possible with SELECT as in:

 

SELECT @variable1 = 'somevalue', @variable2 = 'someothervalue' 

 


Cheers,
Venkatesan Prabu .J
Head, KaaShiv InfoTech
For free Ebook : http://kaashivinfotech.com/Ebooks.aspx 



Cheers,
Venkatesan Prabu .J
Head, KaaShiv InfoTech
http://kaashivinfotech.com/Ebooks.aspx
Found interesting? Add this to:


Experience:9 year(s)
Home page:http://www.dotnetfunda.com
Member since:Tuesday, May 01, 2012
Level:Starter
Status: [Member]
Biography:
>> Write Response - Respond to this post and get points

More Blogs

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/21/2013 1:32:30 AM