In Oracle, when writing dynamic SQL one does something like this:
create or replace procedure myProc(n in number)
as
begin
execute immediate
'update myTable set myColumn = :n'
using n;
commit;
end;
And then ‘magic happens’. What, if any, is the equivalent concept / syntax in SQL Server? (BTW I’m using SQL Server 2005)
You would use
sp_executesql. The bound variables look like this:@var1.From the below link, an example query against the standard Northwind database:
Full details and example syntax are at the following links:
http://msdn.microsoft.com/en-us/library/ms188001.aspx
http://msdn.microsoft.com/en-us/library/ms175170.aspx