Wednesday, November 17, 2010

Default Or Optional Parameters to an SP

Default or Optional Parameters are declared by assigning a default value to them. Then it is not necessary to pass any value to them while calling the SP, it will take the default value in case nothing is passed.

this is very useful,

create proc test
@studentid bigint  = NULL
 if ( @studentid is not null )
 select * from sec45.dbo.DailyAttendanceTable
 where StudentId = @studentid
 select * from sec45.dbo.DailyAttendanceTable
exec test  --returns all rows
exec test 1285  -- returns only  one row

No comments:

Post a Comment