How to get Random values in digits like 1,2,3,4,5 and so on without the decimal point?

 Posted by vishalneeraj-24503 on 10/7/2014 | Category: Sql Server Interview questions | Views: 328 | Points: 40
Answer:

If we want to generate a random integer number,then we have to simply multiply it by the maximum value we want.
For Example:-
SELECT CAST(RAND() * 10 AS INT) AS [OneDigitRandomNumber];
1 digit random number
SELECT CAST(RAND() * 100 AS INT) AS [TwoDigitRandomNumber];
2 digit random number
SELECT CAST(RAND() * 1000 AS INT) AS [ThreeDigitRandomNumber];
3 digit random number
SELECT CAST(RAND() * 10000 AS INT) AS [FourDigitRandomNumber];
4 digit random number
SELECT CAST(RAND() * 100000 AS INT) AS [FiveDigitRandomNumber];
5 digit random number


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response