Though it looks simple it is very difficult to generate random numbers which one can’t guess. There are many different ways to generate random values in SQL Server. I have previously blogged about it over here where I have demonstrated five different methods to generate random values in SQL Server.
SQL SERVER – Random Number Generator Script – SQL Query
In this sixty second video we will see a neat trick where we will generate Random value between specified two numbers.
Let us see the same concept in following SQL in Sixty Seconds Video:
[youtube=https://www.youtube.com/watch?v=1d29ka0hHnc]
Related Tips in SQL in Sixty Seconds:
- SQL SERVER – Random Number Generator Script – SQL Query
- Generate A Single Random Number for Range of Rows of Any Table – Very interesting Question from Reader
- Retrieving Random Rows from Table Using NEWID()
What would you like to see in the next SQL in Sixty Seconds video?
Reference:Â Pinal Dave (https://blog.sqlauthority.com)
1 Comment. Leave new
Dear Pinal,
I am giving one of example of Sql query which I used in SSRS Report. In below example used few sub queries to achieve result. But few more queries are there where lot of sub queries used(15-20) in same manner. Basically what we want the count of record based on different condition. Because of lot of sub queries used in Sql queries its taking lot of time to execute (Performance issue). Is there are any alternate way to achieve same result within minimum time of execution.Please give valuable suggestion/solution.
Example:
SELECT FI.Name,
(SELECT COUNT(*) FROM FilterIncidentTrans AS FIT
WHERE FIT.IsPunUnits=1 AND FIT.RecId=FI.RecId) AS [PUN UNITS COUNT],
(SELECT COUNT(*) FROM FilterIncidentTrans AS FIT
WHERE FIT.IsREBELUnits=1 AND FIT.RecId=FI.RecId) AS [REBEL UNITS COUNT],
(SELECT COUNT(*) FROM FilterIncidentTrans AS FIT
WHERE FIT.IsOtherUnits=1 AND FIT.RecId=FI.RecId) AS [Other UNITS COUNT]
FROM FilterIncident AS FI
WHERE FI.StartDate=@StartDate and FI.EndDate=@EndDate