基于变量表达式更新DB值 [英] Update DB values bases on variable expression
问题描述
employeeid employee salaryheadid actualformula公式类型abb rate
----------- ---------------- -------------------------------------------------- -
96 rakesh 5 {1} - {2} {基本} - {巴士} + rajj null
< pre lang =text> employeeid salaryheadid abb rate
----------- ------------ ------------ ---------- ---------------------
96 1基本336.6667
96 2巴士10.00
salaryheadid abb
-------- ------ ----------
1基本
2巴士
3其他
4 TDS
5 rajj
6税
7 mmm
这里是表1中的3个表employeeid = 96的表是null。
我想设置它的值= 336.6667 - 10 = 326.6667。
公式来自另一个表格p_formula。它可能是任何东西。
基本*公共汽车或其他任何东西。
任何人都可以帮助我。,。
plz用vb给asp溶胶....
添加了代码块,更新了标题 - OriginalGriff [/ edit]
如果您的意思是在另一个表中包含基于文本的列您可以应用于该字段的表达式列表,然后您需要将其读入字符串,并从中构建新的SQL语句,然后执行该操作。所以,例如,如果你有p_formula:
Id Exp
1 rate-10
2 rate + 10
3 rate * 5然后:
DECLARE @Cmd VARCHAR (MAX)
DECLARE @ Exp VARCHAR (MAX)
SET @ Exp = SELECT Exp FROM p_formula WHERE Id = 1
SET @ Cmd = < span class =code-string>' UPDATE MyTable SET rate =''' + @ EXP + ' ''WHERE employeeID = 96 AND abb =''Basic'''
Exec ( @ Cmd )这可能不会做你想要什么,但我不完全理解你的想法 - 这似乎是一种非常奇怪的做事方式,这意味着可能有更好的方法来获得你想要的结果 - 但它给你的一般的想法。
employeeid employee salaryheadid actualformula formula type abb rate
----------- --------------------------------------------------------------------
96 rakesh 5 {1}-{2} {Basic}-{Bus} + rajj null
employeeid salaryheadid abb rate
----------- ------------ ---------------------- ---------------------
96 1 Basic 336.6667
96 2 Bus 10.00
salaryheadid abb
-------------- ----------
1 Basic
2 Bus
3 Other
4 TDS
5 rajj
6 tax
7 mmm
here is 3 tables in table 1 rate for employeeid=96 is null,.
i want to set its value= 336.6667 - 10 =326.6667.
the formula is coming from another tabel p_formula. it may be anything.
basic * bus or anything else.
can anyone plz help me.,.
plz give sol in asp with vb....
[edit]Code block added, title updated - OriginalGriff[/edit]
If you mean that you have a text-based column in a different table that contains a list of expressions you could apply to the field, then you will need to read that into a string, and build a new SQL statement from it, then execute that. So if for example you had p_formula:
Id Exp 1 rate-10 2 rate+10 3 rate*5Then:
DECLARE @Cmd VARCHAR(MAX) DECLARE @Exp VARCHAR(MAX) SET @Exp = SELECT Exp FROM p_formula WHERE Id=1 SET @Cmd = 'UPDATE MyTable SET rate=''' + @EXP + ''' WHERE employeeID=96 AND abb=''Basic''' Exec(@Cmd)That probably won't do what you want exactly, but I don't fully understand your thinking here - it seems like a very odd way to do things, which means there is probably a much, much better way to get the result you want - but it gives you the general idea.
这篇关于基于变量表达式更新DB值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!