logo       

Re: Using dynamic SQL to set a variable: msg#00098

Subject: Re: Using dynamic SQL to set a variable

Ya, I realized after I sent the message that I didn't mention that.  
I'm using SQL Server 2000.  I tried to move it to a UDF, but it's the 
same problem.  

I'll try a couple of other things and report back what I find out.

BTW, thanks for responding!  :)

KRP

--- In padnug@xxxxxxxxxxxxxxx, darthsmily <darthsmily@xxxx> wrote:
> I don't think you can assign a variable from an exec that way.
> usually it's like
> exec @foo = sprocname
> 
> However if it turns out you can and it's some other error, I would 
be 
> very interested in finding out.
> 
> you might want to do something like this:
> 
> begin
> Declare @rowcount as int
> set @rowCount = (SELECT COUNT(*) FROM report)
> print @rowcount
> end
> 
> It just ocucured to me that I am assuming SQL Server.
> 
> darthsmily
> 
> Keith R. Pinster wrote:
> 
> >This is too weird.  I'm trying to loop through my tables to get 
row 
> >counts.  I have a cursor which runs through the tables fine.  In 
the 
> >loop, I execute this statement:
> >
> >SET @rowCount = EXEC ('SELECT COUNT(*) FROM ' + @tableName)
> >
> >and I get an error saying that there is Incorrect syntax near the 
> >keyword 'EXEC'.  However, if I just run the statement:
> >
> >EXEC ('SELECT COUNT(*) FROM ' + @tableName)
> >
> >it works fine.  Can't I set a variable using dynamic SQL this 
way?  I 
> >was sure I had done it before...
> >
> >KRP
> >
> >
> >
> >
> >
> >
> > 
> >Yahoo! Groups Links
> >
> >
> >
> > 
> >
> >
> >
> >
> >
> >  
> >
> 
> 
> -- 
> No virus found in this outgoing message.
> Checked by AVG Anti-Virus.
> Version: 7.0.298 / Virus Database: 265.6.4 - Release Date: 
12/22/2004





------------------------ Yahoo! Groups Sponsor --------------------~--> 
$4.98 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/Q7_YsB/neXJAA/yQLSAA/dpFolB/TM
--------------------------------------------------------------------~-> 

 


<Prev in Thread] Current Thread [Next in Thread>