Click here to Skip to main content
14,969,910 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
S.No, Agent_code , Branch, palmtec_id , min_rec , max_rec , Last_billed

1, 1351 , BG , BG10, BG10000058 , BG10000068, 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) but it doesnt subtract varchar there a way to split the values and subtract ...can anyone help me out..thanks in advance
Updated 23-Feb-21 21:01pm

Hi alia,

try this

select ( cast(RIGHT(max_rec,4) as integer)- cast(RIGHT(min_rec,4)as integer))
alia007 14-Mar-16 8:10am
I got it working ...thanks a lot ..both of u
alia007 14-Mar-16 8:14am
CONVERT(INT, STUFF(Max(max_rec), 1, 1, ''))- CONVERT(INT, STUFF(Min(min_rec), 1, 1, ''))as Received

I used this and got exact result as expected...
Member 15081560 24-Feb-21 3:07am
how did you add the subtracted value in third column? please help.
Use SUBSTRING() and LEN() :
SUBSTRING (Transact-SQL)[^]
LEN (Transact-SQL)[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900