 Hello friends, welcome back. My name is Sushil Singh and this is continuation of SQL Server interview questions and answers. So today I am going to discuss one more question which is related to interviews. In this session, I am going to discuss how we can add only integer values from any string when values are in more than one digit. So in our previous session, I have discussed how we can add values when integer values in our single digit. But in this session, we will understand how we can add the values when they are existing more than one digit. So let's move to another slide where we will understand what it means. So this is our slide. So here you can see we have an input string and we have output. In our input string, you can see you will start from left hand side. So our first numeric value would be one. And then our other numeric value is three. When we move from left to right, then you will get four and then two. So four and two are coming together. So when we are going to concatenate between four and two, then we will get 42. And this 42 is a numeric. So it will be treated as a single unit. Then again, we are going to move. And here you can see we are going to see 181. When we are going to combine these three values, it will 181. So it will treat it as a single unit. And then nine and at last, you will get 10. So this is our input string. When we are going to add numeric values from our input string, then you will get 246 as in output. So how we can achieve in SQL Server. So let's move to SQL Server Management Studio where we will understand how we can achieve this. So I have already typed the code. So you will understand very easily. And we can save the time. So I have declared five variables, our first variable as an input variable, which is where one. So this is our variable variable. And this is our input string. So I have any slides or input string in our address, where one variable, and then length variable in length one variable, I am going to calculate the length of this our input string. So this will be any slides in our length one variable. So now I am going to use a loop. So here, this loop will be executed until unless the value of this address length one variable is greater than zero. So inside this loop, I am going to fetch the value from the left hand side of this input variable. So this input variable has address in our left hand side. The first value will be picked from here. And this value will be any slides in our address T variable. So value it will be any slides in address T variable. Then again, we are going to check inside this loop. If this value is numeric or not, when this address T variable value is numeric, then it will move inside this block. Otherwise, it will move in S block. So in this condition, it will move in S block. So inside this S block, you have that the value of this final variable is equals to address final. And then I am going to add the value of this address interval. By default, it's blank. When we are going to convert in our integer, then it will return zero, because there is no value existing at the rate interval. And then again, I am going to initialize this value by blank. So this S block will be finished here. And when this S block will be finished, I am going to use this at the rate where one, and I am going to remove over this, you know, left hand side first variable. And then again initialize this value in our at the rate one variable. So in where one variable, I am going to remove the first value from left hand side, because I have used this at the rate in our first execution. For another variable is at the rate length one variable, I am going to decrease the value by one. For next time, it will pick the value because our first at the rate has been finished. And then it will move our second at the rate. So it will again go to our S block. When this S block will be executed as a same and final value will be same for the second time. So when these two value will be skipped, then it will move over third third character is one and it will be executed as the numeric. So for third time, it will insert in our inter variable. So in inter variable at the rate T will be concatenate with at the rate interval. So at the rate interval is blank for our first time. And this is one. So this is one. So this S block will be skipped and then move to our next. So here it will one will be skipped and then move to add this has symbol. So this has symbol will be picked for fourth time. And once it will be picked, then it will be checked whether this as is numeric or not. So we know this value is not numeric. So moved to our S block. So inside this S block at the rate final has zero at this time. So at the rate final will be zero. And I am going to use this inter variable. So inter variable value is one as I have discussed. We can convert in our integer and we can simply add with at the rate final. And then I am going to set this inter variable as a blank. Execution will be finished. When it will move to four, then it will be checked and initialize four in our inter variable. And then we will move to two. Then it will again face the value for two and it will be is numeric is true. So it will be concatenate between four and two. So it will be initialize 42 in our inter variable. And then equals to then this condition will not be satisfied. Then it will move to S block. So inside this S block, we can see at the rate final one is equals to address final one plus I am going to add this inter variable value with this final. So it will be added. So it will be executed for all the execution and we will get the result. So once we will executed, we can see we are going to get value of 236. But in our slide we can see we want 246 when we are going to add these all these values. So why this happened because this integer value is exist at the last position. So we don't have any non character value after the integer value. So how we can remove this condition in our code, we have already typed the query. So I am going to uncomment this code. So here for the last execution, I am going to check whether this interval value is numeric or not. Once this value will be find as a numeric, then I am going to add this inter variable value in our final and we will get the final value. So it will be checked for last condition as well. So now we can execute and we can see we will get the appropriate result as we want. So here you can see 246 and in our code we have achieved 246. So I hope you have understand how we can achieve this output by using SQL Server. If you like this video, please subscribe our channel for many more videos. If you need this script, it will be available on my Facebook page. You can copy from there. Thank you so much for watching.