How to Set SQL Variables in Dynamic SQL Text


The following example shows how to use variables for input and output for execution of sql text.  This is handy for stored procedures that use sp_executesql for executing query text against a database.

-- Declare Input/Output Variables
Declare @vc_sql 		nvarchar(4000)	-- MUST BE NVARCHAR
	,@vc_input_Name  	varchar(200)
	,@sdt_output_BirthDay 	Smalldatetime

select @vc_sql = '
Select @sdt_output_BirthDay  = Employee.Birthday
From  dbo.Employee (NoLock)
where  Employee.Name >= ''@vc_input_Name'''

exec sp_executesql 	@vc_sql
			,N'@vc_input_Name varchar(200), @sdt_output_BirthDay Smalldatetime output'
			,@vc_input_Name
			,@sdt_output_BirthDay out
Advertisements

TDD vs. Non TDD

Read an interesting article today comparing the time to develop something with and without TDD.

Here’s information for the lab:

http://parlezuml.com/blog/?postid=1019

Here’s a post with the results:

http://parlezuml.com/blog/?postid=1021