Free Jobs
Reference




Dot Net Forums: ASPNET (77) C#.NET (39) VB.NET (8) AJAX (21) Silver Light (1) WCF (10) WPF (1) WWF (1) .NET 3.5 (3) SQL SERVER (38) Other (3)

Topic: How to declare set values of scalar variables in SQLServer using set or select

To get the Posted Questions details daily in your mail Click Here

Share this Post on Facebook/Twitter/Orkut Bookmark and Share





User: manishav3388 Post Date: 22 Apr 2011 03:20

Introduction:
Many times during sql server programming you will need to declare and set the values of variables in SQL Server queries



Main Content:

ALTER PROCEDURE [dbo].[InsertSettingsData]

 @Param1 VARCHAR(100),

            @Param2  VARCHAR(100),

            @Param3 VARCHAR(100),   

            @Param4 int   

 

AS

declare @Variable1 VARCHAR(100)

declare @Variable2 bit

declare @Variable3 datetime




select @Variable1 = (select Name from Table1 where Name =@Param1 and Status = 1)


or can be done by set .set @LastDate =  (select Name from Table1 where Name =@Param1 and Status = 1  order by DateUpdated desc)




BEGIN


--Write your logic


END



Conclusion:
Note that with set we can use order by but not with select



About Writer:
hello,I am JAVA Developer from Noida.


Writer's Link: http://

Writer's Email:







Comments:
Post Comment





Similar Articles Top ArticlesLatest Articles Other Articles by this Author







www.freejobsreference.com Copyright © 2009-2011 | All Rights Reserved
All content of this website is protected by copyright laws and should not be reproduced in any form or by any means without written permission
(Best viewed in IE 8.0+ or Firefox 3.0+ at resolution of 1024 * 768 or higher)