Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Variable with Select Value.

Author  Topic 

davidshq
Posting Yak Master

119 Posts

Posted - 2006-05-23 : 17:45:31
I need to compare a variable value I pass to a stored procedure to a select statement, and then make an update statement based upon the result of this comparison. Here is some pseudo-code, can anyone help me figure out the real code?
If @varFruit = select colFruit from tblFoods where ID=
BEGIN
UPDATE tblOrders (name) VALUES (@varFruit)
END
Else
...
David.

- http://www.gamesecretary.com/
- http://www.thehungersite.com/
- http://www.grid.org/

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-05-23 : 18:09:57
What is this statement supposed to do?
If @varFruit = select colFruit from tblFoods where ID=

This would update every row in table tblOrders with the value of @varFruit, if it was valid syntax (it isn't).
UPDATE tblOrders (name) VALUES (@varFruit)


Instead of pseudo-code, it would be better if you explained what you are trying to do. It would be helpful if you posted the table structure and some sample data.



CODO ERGO SUM
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2006-05-23 : 18:59:41
wild guess - no real reason behind it or much connection with your description.


update tblOrders
set name = f.colFruit
from tblOrders o
join tblFoods f
on o.Food_id = f.Food_id
where OrderTypeID = @varFruit

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -