Re: Dynamic query to store record count in variable????

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Andrew J. Kelly (sqlmvpnooospam_at_shadhawk.com)
Date: 12/01/04


Date: Wed, 1 Dec 2004 13:40:49 -0500

Have a look here:

http://www.sommarskog.se/dynamic_sql.html
http://www.support.microsoft.com/?id=262499

-- 
Andrew J. Kelly  SQL MVP
"Chris" <Chris@discussions.microsoft.com> wrote in message 
news:292BA190-F8FD-4696-A6EA-8EE930095F5A@microsoft.com...
> Hello everyone,
>
> I am attempting to write a stored procedure to retrieve the record count 
> but
> have failed so far.  Here's what I have tried...
>
> SET @value = 'SELECT COUNT(*) FROM ' + @tablea
> EXECUTE sp_executesql @sql
>
> ...but this just ends up displaying the count to the screen, so I did....
>
> SET @value = 'DECLARE @tablea_count NVARCHAR(128) SELECT
> @tablea_count=COUNT(*) FROM ' + @tablea
> EXECUTE sp_executesql @sql, @tablea_count OUTPUT
>
> but this doesnt seem to work either.
>
> Help???
> -- 
> Chris 


Relevant Pages

  • Scheduled DTS package doesnt run
    ... I created a DTS package wich runs a standard Stored Procedure in the master ... I call the stored procedure by an Execute SQL Task object with all necesarry ... When I log on as administrator on the server and run the package manually it ... Error string: SQL Web Assistant: Could not execute the SQL statement. ...
    (microsoft.public.sqlserver.dts)
  • Re: Issue with retrieving large data over web using Stored Procedu
    ... It appears that it was hitting the stored procedure, ... Is there any tool in the SQL Profiler that analyze each Trace? ... The maximum amount of time for a script to execute was exceeded. ... do it at ASP. ...
    (microsoft.public.inetserver.asp.db)
  • Re: user permissions
    ... I'm not sure how that would work with the security as the kill sql command is ... I would like to add some comments regarding 'EXECUTE AS' clause in SQL ... this issue by creating a stored procedure with 'EXECUTE AS' clause in SQL ... Microsoft Online Community Support ...
    (microsoft.public.sqlserver.security)
  • Re: Create Storedprocedure with VB6? Is this possible?
    ... you can create and execute an SQL query that includes the ... can SQL Server Management Studio." ... Can VB6 create a stored procedure on the fly. ... Call the connection's Execute method, ...
    (microsoft.public.vb.database.ado)
  • Re: ASP and stored procedure problem (syntax error ?)
    ... I am typing execute sp_sel_companynames @sql, I think this is why it is ... falling over. ... >> page to the stored procedure to return a recordset that i can write ...
    (microsoft.public.inetserver.asp.db)