这样的SQL语句可以实现吗

yangchuzi 2004-01-19 11:03:50
关于工资系统的一个表
id bh mon
1 :g2@ 100
2 :g4@ 150
3 (:g2@+:g4@)*0.8
我想像id=3的记录一样,如果有公式的,系统能把数据计算出来,然后填在mon字段中
...全文
66 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
w_rose 2004-01-20
  • 打赏
  • 举报
回复
如果你使用“:”和"@"号等
------------------------------>>>>
如果你不使用“:”和"@"号等
w_rose 2004-01-20
  • 打赏
  • 举报
回复
既然你们把变量定义成这种丑八怪模样,就只好在生成动态查询语句的时候对变量做一些变通(例如用A_A_A_代替:,用X_X_X_代替@)。
w_rose 2004-01-20
  • 打赏
  • 举报
回复
如果你使用“:”和"@"号等,那么写一个通用的动态查询就行了。

根据非公式记录生成变量声明和赋值语句,公式记录则生成update语句。
zjcxc 元老 2004-01-20
  • 打赏
  • 举报
回复
create proc p_calc
as
declare @s varchar(8000)
declare tb cursor for select s='update 表 set mon=('+bh+') where id='+cast(id as varchar) from 表
open tb
fetch next from tb into @s
while @@fetch_status=0
begin
exec(@s)
fetch next from tb into @s
end
close tb
deallocate tb
zjcxc 元老 2004-01-19
  • 打赏
  • 举报
回复
--创建一个存储过程来计算就行了.
create proc p_calc
as
declare @s varchar(8000)
declare tb cursor for select s='update 表 set mon=('+bb+') where id='+cast(id as varchar) from 表
open tb
fetch next from tb into @s
while @@fetch_status=0
begin
exec(@s)
fetch next from tb into @s
end
close tb
deallocate tb

北京菠菜 2004-01-19
  • 打赏
  • 举报
回复
关注,帮你顶一下

34,591

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧