减去两个varchar列并将结果存储在第三列中 [英] Subtract two varchar columns and store result in third column
问题描述
S.No - > 1
Agent_code - > 1351
分支 - > BG
palmtec_id - > BG10
min_rec - > BG10000058
max_rec - > BG10000068
Last_billed - > 16-02-2016
我要减去68 -58并存储在第三栏
例如:68-58 = 10
我尝试了什么:
我曾尝试过(max_rec - min_rec)坚果它不会减去varchar列..有没有办法分割值和减去...任何人都可以帮助我..提前谢谢
SELECT CAST(REPLACE(max_rec,BRANCH,' ') as INT ) - CAST(REPLACE(min_rec,BRANCH,' ') as INT )
选择CAST(右(@max_rec,2)为int) - CAST(右(min_rec,2)为int)
试试这个
SELECT(RIGHT(max_rec,2) - RIGHT(min_rec,2))FROM table_name;
S.No -> 1
Agent_code -> 1351
Branch -> BG
palmtec_id -> BG10
min_rec -> BG10000058
max_rec -> BG10000068
Last_billed -> 16-02-2016
I want to subtract 68-58 and store in third column
for ex: 68-58 =10
What I have tried:
I had tried (max_rec - min_rec) nut it doesnt subtract varchar columns..is there a way ti split the values and subtract ...can anyone help me out..thanks in advance解决方案SELECT CAST(REPLACE(max_rec, BRANCH, '') as INT) - CAST(REPLACE(min_rec, BRANCH, '') as INT)
select CAST(Right(@max_rec ,2) as int) - CAST(Right(min_rec ,2) as int)
Try this
SELECT (RIGHT(max_rec,2) - RIGHT(min_rec,2)) FROM table_name;
这篇关于减去两个varchar列并将结果存储在第三列中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!