dbTalk Databases Forums  

Syntax of updating table variables?

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Syntax of updating table variables? in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
sean.gilbertson@gmail.com
 
Posts: n/a

Default Syntax of updating table variables? - 03-10-2006 , 11:48 AM






Hi,

I have a user-defined function which returns a table (call it '@a'),
and has another table defined as a variable (call it '@b'). When I try
to do the following query, I get "Must declare the variable '@b'" and
"Must declare the variable '@a'." How do I remedy this?

The query:

UPDATE @a
SET
stuff =
(SELECT otherStuff From @b
WHERE @b.someID = @a.someID)


Reply With Quote
  #2  
Old   
David Portas
 
Posts: n/a

Default Re: Syntax of updating table variables? - 03-10-2006 , 12:08 PM






sean.gilbertson (AT) gmail (DOT) com wrote:
Quote:
Hi,

I have a user-defined function which returns a table (call it '@a'),
and has another table defined as a variable (call it '@b'). When I try
to do the following query, I get "Must declare the variable '@b'" and
"Must declare the variable '@a'." How do I remedy this?

The query:

UPDATE @a
SET
stuff =
(SELECT otherStuff From @b
WHERE @b.someID = @a.someID)
Have you declared your table variables? Assuming you have you still
need to use an alias. Variable names aren't valid as aliases:

DECLARE @a TABLE (someid INT, stuff INT);
DECLARE @b TABLE (someid INT, otherstuff INT);

UPDATE A
SET stuff =
(SELECT B.otherstuff
FROM @b AS B
WHERE B.someID = A.someID)
FROM @a AS A ;

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/m...S,SQL.90).aspx
--



Reply With Quote
  #3  
Old   
sean.gilbertson@gmail.com
 
Posts: n/a

Default Re: Syntax of updating table variables? - 03-10-2006 , 01:17 PM



David,

PERFECT. You hit the nail on the freaking head. THANK YOU so much!!

Take it easy and have a good day!!

- Sean


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.