[SQL]update语句中where条件数值能否用一个常量或变量代替呢?
语句如下:update表1setfname=(selectfnamefrom表2wherefitem='4'andfnumber='123')wherefnumber='...
语句如下:update 表1 set fname = (select fname from 表2 where fitem = '4' and fnumber = '123') where fnumber = '123'
经常会使用这类语句,数值123是每次都不一样的,有什么方法能替代123?只输入一次啊?现在必须输入2个123 展开
经常会使用这类语句,数值123是每次都不一样的,有什么方法能替代123?只输入一次啊?现在必须输入2个123 展开
3个回答
展开全部
DECLARE @number varchar(80)
SET @number= '123'
update 表1 set fname = (select fname from 表2 where fitem = '4' and fnumber =@number) where fnumber = @number
SET @number= '123'
update 表1 set fname = (select fname from 表2 where fitem = '4' and fnumber =@number) where fnumber = @number
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
update 表1 set fname=b.fname
from 表1 a,表2 b
where a.fnumber=b.fnumber
and b.fitem='4'
and fnumber='123'
from 表1 a,表2 b
where a.fnumber=b.fnumber
and b.fitem='4'
and fnumber='123'
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
试试以下语句
with mtbl as ( select '123' as mycode from dual)
update 表1 set fname = (select fname from 表2 where fitem = '4' and fnumber in (select mycode from mtbl)) where fnumber in (select mycode from mtbl)
with mtbl as ( select '123' as mycode from dual)
update 表1 set fname = (select fname from 表2 where fitem = '4' and fnumber in (select mycode from mtbl)) where fnumber in (select mycode from mtbl)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询