Re: Error--Update Staement

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

From: Steve (Steve_at_discussions.microsoft.com)
Date: 11/05/04


Date: Fri, 5 Nov 2004 14:26:02 -0800

Thanks :)

"Aaron [SQL Server MVP]" wrote:

> You've declared @a as a variable, then you are trying to run an update
> statement against that variable. UPDATE statements cannot apply to
> variables, but I think you can do what you are trying to do using dynamic
> SQL.
>
> http://www.sommarskog.se/dynamic_sql.html
>
> --
> http://www.aspfaq.com/
> (Reverse address to reply.)
>
>
>
>
> "Steve" <Steve@discussions.microsoft.com> wrote in message
> news:0FD7AEDA-8FA7-4C45-BE48-15E9D4A4F114@microsoft.com...
> > Hi,
> > I am getting error when I run the following statement
> >
> >
> >
> >
> > declare @a nvarchar(255)
> > select @a = tblname from logtbl where tblname like 'orders%'
> > and logtbl.logdate > getdate() - .5
> >
> > update @a
> > set @a.log_id = l.log_id
> > from @a , logtbl l
> > where l.logdate > getdate() - .5
> > l.tblname like 'orders%'
> >
> >
> > Server: Msg 137, Level 15, State 2
> > Must declare the variable '@a'.
> >
> > Plz.help
>
>
>