Re: How to retrieve results from a dynamic SQL query

Tech-Archive recommends: Speed Up your PC by fixing your registry



On Jun 18, 7:52 pm, Ed Murphy <emurph...@xxxxxxxxxxxx> wrote:
James.Shih.Neul...@xxxxxxxxx wrote:
On Jun 15, 6:16 pm, Ed Murphy <emurph...@xxxxxxxxxxxx> wrote:
InvestorTrade wrote:
I have a query that is formed dynamically, and I need to be able
store the result in a variable, and example of this would be:
BEGIN
DECLARE @myresult int
DECLARE @query = 'select count(*) from sysobjects'
SET @myresult = exec (@query)
END
I thought of using Global temporary tables (##) where I could store
the result, but I rather not.
Can you replace the query with a stored procedure?

Yes, but how would a store procedure help? I need to store the result
of the query

Because you can feed the output of the stored procedure into a
(non-global) temporary table. Quick example:

create procedure foo as
begin
select bar, baz from the_table
end

create table #foo (bar int, baz varchar(10))

insert into #foo exec foo

select * from #foo

OK - Yes - I knew about the temporary table and already thought about
this too - but I don't want to use it - I think it might be cheaper to
use memory than creating a temp table in the drive - unless temp
tables are created in memory. Thank you for the suggestion, any other
way you may think of?

.



Relevant Pages

  • Re: How to retrieve results from a dynamic SQL query
    ... DECLARE @myresult int ... Can you replace the query with a stored procedure? ... create procedure foo as ...
    (microsoft.public.sqlserver)
  • Re: Strange query - Oracle Text problems?
    ... below) just to show that in this case, the query proceeds efficiently. ... FROM FOO ... With the Partitioning, Oracle Label Security, OLAP and Oracle Data ... SQL> DROP TABLE FOO; ...
    (comp.databases.oracle.server)
  • Re: sqlParameter and NULL
    ... SqlCommand cmd = new SqlCommand("SELECT idx FROM foo WHERE ... SqlParameter para = new SqlParameter; ... strings to the query (e.g. string.concat("SELECT * FROM foo WHERE col ... Hitchhiker's Guide to Visual Studio and SQL Server ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Optimising queries
    ... optimising a query with regard to indexes. ... it matters what index on 'foo' that you have. ... pick one and make it (foo, barney) or. ... SQL Server may use index intersection. ...
    (comp.databases.ms-sqlserver)
  • Re: cant get join on two large tables to use_nl or indexes
    ... and property = 'FOO' ... If I do a select countfrom the above query and add RULE to the ... Oracle to access all of the rows?). ... my_other_table mot ...
    (comp.databases.oracle.misc)