在不使用光标的情况下增加值 [英] increasing value without using cursor
本文介绍了在不使用光标的情况下增加值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
create table #tmpTable
(
ProductName varchar(200),
Price float
)
insert into #tmpTable values('Cake',10),('Chocolate',20),('bun',30),('bisckit',40)
select * from #tmpTable
drop table #tmpTable
如何在不使用游标的情况下将蛋糕面包和饼干的价值增加10并在5的情况下进行调味
how to increase value of cake bun and biscuit by 10 and choclate by 5 without using cursor
推荐答案
有一种方法可以使用 Update语句在存储过程中的插入语句之后.
There is a one way that u can use Update statement after insert statement in your stored procedure.
仅更新您可以增加.如何使用光标增加?
uisng update only u can increase .how to increase using cursor?
您要在表中循环,在哪里可以找到巧克力/小圆面包/蛋糕,在哪里可以找到饼干,在哪里可以找到饼干..将价格提高5吗?
您可以2way进行.
1.编写update语句,该语句将更新所有对应的行.
Do you want to loop through the table and where ever you find choclate/bun/cake by 10 and where you find biscuit..increase the price by 5?
You can do it in 2ways.
1.Write update statements which will update all the corresponding rows.
update #tempTable set price =price+ 10 where productname in (''Choclate'',''Bun'',''Cake'');
update #tempTable set price =price+ 5 where productname=''Biscuit''
2.使用光标在表中循环浏览,并逐行更新表.
请参见下面的示例
2. Loop through the table using a cursor and update the table accoridingly row by row.
See the below example
DECLARE vendor_cursor CURSOR FOR
SELECT BusinessEntityID, Name
FROM PurchasingVendor;
OPEN vendor_cursor;
FETCH NEXT FROM vendor_cursor
INTO @vendor_id, @vendor_name;
WHILE @@FETCH_STATUS = 0
BEGIN
..... Do your updates here
希望这会有所帮助.
Hope this helps.
这篇关于在不使用光标的情况下增加值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文