 Hello, welcome to SSUnited, so since this side and this is continuation of SQL Server interview questions and answers. So today we are going to discuss one more interview question that is how to check the Armstrong numbers. So what is Armstrong number and how we can check it. So let's move to next slide to understand about the Armstrong number. So here as we can see the first number that is 153. So first we need to get the length of this so that would be 3. Then we need to take the separate numbers that is 153. Then we need to take the power with the length that would be 3. And then we need to add those numbers. If that number will be equals to 153 that is existing number then that would be Armstrong numbers otherwise not. As we can see in the last that would be 1634 so length of this is 4 and we need to take the separate characters that would be 163 and 4. Then we need to take the power with the 4 and then we need to add those numbers. If that number will be equals to our input number that is 1634 that would be Armstrong number. So here we need to write a function that will accept a parameter with the number and we need to write our logic inside the function. If that number is Armstrong number then we just want to print the Armstrong number otherwise we need to print the given number is not Armstrong number. So let's move to Sikosovo management studio where we will write the query and we can get the output. So here I am using sql2o17 so you may have another version of Sikosovo. So first of all I would like to declare a variable that would be our input variable. So we can say like input and it would be work at type and this is 100. Now we can set the value like 153 inside this variable. Now I need to declare few more variables. So next variable would be length data type would be integer and we can set the value of this variable length of our input. Now we need to declare one more variable that would be final variable. So in the final variable it will be going to combine the result set. Then I need to declare one more variable that would be i and initial value we can set as length of our input. So we have done our variables. Now we need to write our logic. So first of all we need to use while loop if this add rate i value is greater than 0 this loop will be executed and here we can write begin then end. So here we can set add rate final variable should be equals to add rate final plus. Here we need to take the power with each characters so we can use power and here we need to fetch out one by one so we can use substring. So this is substring function and inside the substring function we just want to get values from the input. So this is input then we can specify add rate i and we just want only one character. We can put comma and here we can use add rate length. Next we just want to decrease the value of this add rate i variable. So add rate i minus one. Now we have done our loop. So what we are going to deal with this loop? So here we will calculate the length of this input. So length variable will hold 3 and this i will also going to hold 3. So here it will be going to start from input that is 153 and here that is 3 we need to pull only one character. So it will be going to get 3 at the first time. And here we have length that is 3 so 3 to power 3 in the first execution then in the second execution it will be going to pick second character and in the third execution it will be going to pick the first character and it will be going to add those values into add rate final. Now we can check so here we can use if add rate input is equals to add rate final. So that value will be armstrong number. So we can use begin and so we can print the message like given number is armstrong. And if these values is not going to equal then we can print given number is not armstrong. So here we can use print given number is not armstrong now we can execute. So given number is armstrong that is good. Now we can change this number given number is not armstrong. Now we need to put this into a function so we can create a function. So that would be the function and it would be fn dot get strong and it will be going to accept a parameter so we can call this as input and data type would be where care and it is 100. Now we have to specify the returns and data type. So this is where care and 100 now we can use as then we can use begin now it looks good but here we need to make some changes. So this else is statement should not be there now it looks good and here we have already declared the input parameter so we have to comment this now let me execute this. So now function is created let me copy this and we just want to check it's working fine or not. So select and here we can use dbo dot or function and here we can specify the value. So first of all 153 now we can execute given number is armstrong then 143 given number is not armstrong so it is working fine now 100 now it looks good then we can check for last value that is 1634 execute so given number is armstrong. So this is the code and this is very simple if you can understand step by step so this is the function as we have created. So thank you so much for watching this video if you like this video please subscribe our channel to get many more videos. If you need this script it will be available on the description of this video so you can copy from there. Thank you so much for watching.