Home > Archive > Microsoft SQL Server forum > June 2005 > Re: Executing Simple Statements - Newbie









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Executing Simple Statements - Newbie
Simon Hayes

2005-06-10, 3:23 am

sp_executesql is probably the best option:

declare
@s varchar(100),
@sql nvarchar(4000),
@i int

set @s = '5+6+9'
set @sql = 'set @i = ' + @s
exec sp_executesql @sql, N'@i int output', @i = @i output
select @i

But in general dynamic SQL can be awkward and there are a number of
important issues to consider - see here for the full story:

http://www.sommarskog.se/dynamic_sql.html

Alternatively, you could do this easily in a front-end application, and
if you have more complex formulae to evaluate then that might be a
better option.

Simon

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2009 droptable.com