Saturday, February 25, 2012

macro substitution or command @var

In VFP we can use in the program the variable
var ='some_statement'
var && here will be 'some_statement'
&var && here will be some_statement
In SQL Server if we have :
declare @.var varchar(8000)
set @.var='some_statement'
In the program
@.var --here will be 'some_statement'
But if we want to use the variable @.var the same way as in the second
variant what we should do ?Can you give an example of 'some_statement'?
If that's a T-SQL statement lookup EXECUTE and sp_executesql in Books Online
.
However, we can provide a more appropriate solution if you share some more
information. You can start by explaining what exactly you are trying to do.
ML|||Why do you want to use dynamic code? When I worked on VFP our
development standards only permitted macro substitution in very
exceptional cases - and rightly so. Dynamic code is hard to test, debug
and maintain and in my experience its use in production code is usually
the result of poor design or laziness.
Dynamic SQL does have certain "legitimate" uses for DBA type tasks, and
for those we have the EXEC and sp_executesql statements.
David Portas
SQL Server MVP
--|||Thank you.
"ML" wrote:

> Can you give an example of 'some_statement'?
> If that's a T-SQL statement lookup EXECUTE and sp_executesql in Books Onli
ne.
> However, we can provide a more appropriate solution if you share some more
> information. You can start by explaining what exactly you are trying to do
.
>
> ML|||Thank you.
"David Portas" wrote:

> Why do you want to use dynamic code? When I worked on VFP our
> development standards only permitted macro substitution in very
> exceptional cases - and rightly so. Dynamic code is hard to test, debug
> and maintain and in my experience its use in production code is usually
> the result of poor design or laziness.
> Dynamic SQL does have certain "legitimate" uses for DBA type tasks, and
> for those we have the EXEC and sp_executesql statements.
> --
> David Portas
> SQL Server MVP
> --
>

No comments:

Post a Comment