View Single Post

   
  #2 (permalink)  
Old 02-28-2008, 08:25 PM
Erland Sommarskog
 
Posts: n/a
Default Re: exec(select...), how supress the output?

(foldface@yahoo.co.uk) writes:
> I have a dynamically constructed sql query that I want to execute, e.g.
> exec('select * from ' + @tablename)
>
> (1) Can I suppress the output somehow if this returns no values?


EXEC ('IF EXISTS (SELECT * FROM ' + @tablename ' + ') SELECT * FROM ' +
@tablename)

> (2) Can I use the result of this query in another query somehow? e.g.
> select


INSERT #tmp (...)
EXEC('...')

> (3) Can I control the size of the columns in the output somehow


This question is unclear. Output columns from SQL Server does not
really have any size, but that is up to the client tool you use.

But if you are using Query Analyzer, and want some nice output there,
you can use convert(varchar(n), ...) where n is the size of your choice.

--
Erland Sommarskog, SQL Server MVP, sommar@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Reply With Quote