hello
I have a cell with following value inside '5+2'
how to retrieve this as result 7 ?
any tips are appreciated
thanks
rgds
Technology Tips and News
hello
I have a cell with following value inside '5+2'
how to retrieve this as result 7 ?
any tips are appreciated
thanks
rgds
Are you looking for the below?
create Table BESTB (col1 varchar(100)) Insert into BESTB Values('5+2') Declare @s nvarchar(MAX)='' Set @s = (Select 'Select '+ Col1 From BESTB) EXECUTE sp_executesql @s Drop table BESTB
I am trying to do something for the guy but if you have more than one row your code retrieves
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
Anywayt I do not understand your code, I mean, you set @s as varchar(max) but what I do not understand is (Select 'Select '+ Col1 From BESTB)...you select a 'select'+col1...no, I do not understand...
I am preparing another type of code
DIEGOCTN,
The question was not clear as OP has not given any DDL or sample data, so I was just trying to understand what OP is looking for with some sample data.
To answer your question,
Try the below:
create Table BESTB (id int, col1 varchar(100)) Insert into BESTB Values(1,'5+2') Insert into BESTB Values(2,'5+3') Insert into BESTB Values(3,'15+43') Declare @s nvarchar(MAX)='' Select @s = @s+ 'Select '+ Col1 + ';' From BESTB EXECUTE sp_executesql @s Drop table BESTB
Assuming that you have only + you can use:
create table forum4 (nation varchar(6), premium varchar(6)) insert into forum4 values ('Spain','4+3'),('France','10+6'),('Italy','11+22') with cte as (select nation, premium, cast(left(premium,CHARINDEX('+',premium,1)-1) as int) as fir, substring(premium, CHARINDEX('+',premium,1)+1,len(premium)-CHARINDEX('+',premium,1)) as sec from forum4) select nation,fir+sec from cte
yes;
thank you
rgds
Lateesh but you retrieves three different queries...select 5+2, select 5+3...I understand your code now.
Cheers