Re: EXEC (select... ) problem Help!



Here's an example on how to build a dynamic SQL string and run it with
EXECUTE or SP_EXECUTESQL stored procedure

http://www.dandyman.net/sql/samples/dynamicsql.txt


--
Dandy Weyn
[MCSE-MCSA-MCDBA-MCDST-MCT]
http://www.dandyman.net

Check my SQL Server Resource Pages at http://www.dandyman.net/sql
"Scagnetti" <Scagnetti@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:7363AFA0-2098-4014-9BEB-FFF6F5D697DC@xxxxxxxxxxxxxxxx
> How can I get this to work?
> declare @WkEmpID
> declare @sql varchar(1000)
>
> set @sql = 'select distinct @WkEmpID = EmpID from Employee'
> exec (@sql)
>
> Now this is a simplified version of a more comples query which is forcing
> me
> to use this method rather than a simple SQL query. The big problem is
> getting
> the 'EmpID' value into the local variable of '@WkEmpID'. Please help!


.



Relevant Pages

  • Re: Profiler Bug viewing trace flat file?
    ... Kalen Delaney, SQL Server MVP ... Run this code to create a trace capture of the RPC:Complete event: ... declare @error INT ... Now open the trace file in Profiler and you will see that the Textdata ...
    (microsoft.public.sqlserver.tools)
  • Re: Performance Issues With Query
    ... SQL Server MVP ... > DECLARE @Timestamp datetime ... > DECLARE @CallEventName varchar ... > UPDATE CallByCallYesterdayFinal SET Script = SUBSTRING(@Destination, ...
    (microsoft.public.sqlserver)
  • Re: Problem with SQL UDF
    ... DECLARE RLIB VARCHAR; ... DECLARE RVAR CHARDEFAULT ' '; ... In SQL reference, I found that, if not explicitly declared in a declare procedure statement, all arguments inside a variable will be considered of type INOUT, so I assumed that should run as is, but it's not. ...
    (comp.sys.ibm.as400.misc)
  • Re: return a value using MDX
    ... I created a stored procedure to this query. ... it is looking for @sql as well. ... DECLARE @sql varchar ...
    (microsoft.public.sqlserver.olap)
  • Re: Profiler Bug viewing trace flat file?
    ... I tested this on SQL 2005. ... problem as all the trace files get loaded into SQL through ... I guess you are correct in that fn_trace_gettable may derive the Textdata ... declare @TraceID int ...
    (microsoft.public.sqlserver.tools)