"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Thursday, November 24, 2011

Assign Value to a variable on Store Procedure

Hi *.*,
Assign Value to a variable on Store Procedure. First declare a variable with prefix '@'.Then you can use both 
SET and SELECT.


Samples



Declare @DemoVariable nvarchar(50)

SET @DemoVariable = 'Some string'
set @DemoVariable = (SELECT FirstName FROM Students where StudentId = 2)

SELECT @DemoVariable = 'Some string'
SELECT @DemoVariable = FirstName FROM Students WHERE StudentId = 2
SELECT @id = COUNT(*) FROM Students


If u had any trouble just ask, Happy to help u :) 

Stay Tune... 
Have a nice day... 'N happy Coding :)

No comments: