I am running this Blog to help other guys, who are looking some bits and pieces in terms of MS technology....
Monday, June 23, 2008
Select top n random rows from a table in SQL SERVER...
The snag is that SQL doesn't permit the selection of random rows. The good news is that there's a simple trick to getting this functionality to work in SQL.
The solution is based on the uniqueidentifierdata type. Unique identifiers, which are also called Guaranteed Unique Identifiers (GUIDs), look something like this:
4C34AA46-2A5A-4F8C-897F-02354728C7B0
SQL Server uses GUIDs in many contexts, perhaps most notably in replication. You can use them when normal incrementing identity columns won't provide a sufficient range of keys. To do this, you create a column of type uniqueidentifierwhose default value is NewID(), like this:
CREATE TABLE MyNewTable
(
PK uniqueidentifier NOT NULL DEFAULT NewID(),
AnotherColumn varchar(50) NOT NULL
,
. . .
This function is just the ticket to solve our random rows problem. We can simply call NewID() as a virtual column in our query, like this:
select top 4 Column_Name,NEWID() AS RANDOM from TABLE order by RANDOM
Friday, June 13, 2008
Random Number Generator...
Method 1 : Generate Random Numbers (Int) between Rang
-- Create the variables for the random number generation
DECLARE @Random INT;
DECLARE @Upper INT;
DECLARE @Lower INT
-- This will create a random number between 1 and 999
SET @Lower = 1 -- The lowest random number
SET @Upper = 999 -- The highest random number
SELECT @Random = ROUND(((@Upper - @Lower -1) * RAND() + @Lower), 0)
SELECT @Random
Method 2 : Generate Random Float Numbers
SELECT RAND( (DATEPART(mm, GETDATE()) * 100000 )
+ (DATEPART(ss, GETDATE()) * 1000 )
+ DATEPART(ms, GETDATE()) )
Method 3 : Random Numbers Quick Scripts
-- random float from 0 up to 20 - [0, 20)
SELECT 20*RAND()
-- random float from 10 up to 30 - [10, 30)
SELECT 10 + (30-10)*RAND()
--random integer BETWEEN 0
AND 20 - [0, 20]
SELECT CONVERT(INT, (20+1)*RAND())
--random integer BETWEEN 10
AND 30 - [10, 30]
SELECT 10 + CONVERT(INT, (30-10+1)*RAND())Method 4 : Random Numbers (Float, Int) Tables Based with Time
DECLARE @t TABLE( randnum float )
DECLARE @cnt INT; SET @cnt = 0
WHILE @cnt <=10000
BEGIN
SET @cnt = @cnt + 1
INSERT INTO @t
SELECT RAND( (DATEPART(mm, GETDATE()) * 100000 )
+ (DATEPART(ss, GETDATE()) * 1000 )
+ DATEPART(ms, GETDATE()) )
END
SELECT randnum, COUNT(*)
FROM @t
GROUP BY randnum
Method 5 : Random number on a per row basis
-- The distribution is pretty good however there are the occasional peaks.
-- If you want to change the range of values just change the 1000 to the maximum value you want.
-- Use this as the source of a report server report and chart the results to see the distribution
SELECT randomNumber, COUNT(1) countOfRandomNumber
FROM (
SELECT ABS(CAST(NEWID() AS binary(6)) %1000) + 1 randomNumber
FROM sysobjects) sample
GROUP BY randomNumber
ORDER BY randomNumber
Friday, May 30, 2008
C# InterView Questions....
Read C# in more descriptive and easy way
Read c#.net in more descreptive and easy way..
To read more Jokes......
2. A guy was trying to console a friend...
3. A hundred prostitutes in Washington D.C. were asked...
4. An old man was critically ill...
5. Little Johnny catches his parents going at it...
6. A man walks into a pharmacy, buys a condom...
7. A guy steps into an elevator and...
8. Soft and Hard
9. Whats the difference between a blond and a Mosquito?
10. A beautiful, voluptuous woman went to a gynecologist...
11. Pray hard
12. Charlie was in a bar and three babes came up and...
13. What is the definition of ultimate rejection?
14. A penis study
15. Fortunate ingenuity
16. A woman accompanied her husband to the doctors office...
17. Excuse TO smoke
18. A beautiful, voluptuous woman goes to a gynecologist...
19. Twice a day
20. Proffessional Terms
21. A new way to loose weight
22. A guy was sitting in a bar when a stranger...
23. The Perfect Worker
24. No $
25. Little Gregory wakes up in the middle of the night...
26. How does Michael Jackson pick his nose?
27. This man was having problems getting it up to have sex...
28. True love
29. There was this boy in high school that was what you would call...
30. Good News, Bad News, Worse News VII
31. Little Johnny was in his math's class one day...
32. One day, a young cowboy and a cowgirl decided...
33. A guy is screwing a great looking blonde...
34. A little boy was excited about his first day at school...
35. A horny young man went to a brothel...
36. An infamous stud with a long list of conquests...
37. Appropriate punishment
38. Why I Fired My Secretary
39. A man wonders if having sex on the Sabbath is a sin...
40. Paying Rent
41. A little girl was walking along a beach in California...
42. A clear moral
43. A horrible curse
44. Nauseous sex
45. It's dark in here
46. What did the hurricane say to the coconut tree?
47. Ed, Ted and their wives went out camping one weekend...
48. Trouble with the car
49. The Seven Most Important Men in a Woman's Life
50. Beep-beep
51. The subway car was packed...
52. I HAD A BAD DAY
53. What is the most insensitive part of a penis?
54. Golf lessons
55. What do you do if a blond throws a grenade at you?
56. A unit in sex education was about to begin...
57. This guy unexpectedly got the day off and decided...
58. On a very cold winter night...
59. A teacher, a garbage collector, and a lawyer wound up together at the Pearly Gates...
60. On their first night to be together...
61. A man moves into a nudist colony...
62. Working With The FBI
63. A farmer and his wife were laying in bed one night...
64. The same thing
65. Communication problem
66. A dubious remedy
67. Brand new
68. A middle manager is called into his bosses office...
69. Jane was a first time contestant on the $65,000 quiz show...
70. All the same
72. Some people are sitting in a bar...
73. Crazy Sally went to her gynecologist...
74. A group of Americans was touring Ireland...
75. Stuttering animal
76. Two law partners leave their office and go to lunch...
77. A man was being interviewed for a job...
78. A convincing lesson
79. Clinton died and was standing at hte Pearly Gates...
80. Cheap widow
81. A marine general, an army general and a navy admiral...
82. What do you call a gay bar that has no chairs?
83. Golfing
84. The medical student was asked four reasons...
85. An old man and an old woman were sitting...
86. The three wishes
87. The price decides everything
88. Peanuts
89. Chanowski & his other Polak drinking buddy are sitting...
90. Sue and Sally meet at their 30th class reunion...
91. I went past a plastic surgeon's shop...
92. George W. Bush was passing through an airplane terminal...
93. Merry...ied talk
94. Bad news
95. A state trooper pulled a car over...
96. Great A Hot & Juicy Story
97. Two Tourists
98. Punishment that fits the crime
99. Blondes dumb?!?!?
100. One day a blonde went into Wal-Mart and...
Tuesday, May 20, 2008
To get more information of Java script use bellow link...
http://jennifermadden.com/javascript/stringSubstring.html
Split the String values with a special character in MS Flow to convert this into Array
Many times we have a requirement to prepare the Mailing address for some of the documents, suppose there are Address Line1, Address Line2, ...
-
Sometimes you experienced when you have subgrid in your CRM Form, but when you click the ‘expand’ button to expand the view then it will re...
-
I have a web service that takes a serialize string and saves it. This works fine for "small" files, but once I hit a large siz...
-
In CRM 2011, I found a way to add color to entities grids using the ribbon, even if there are still two limitations: 1) This is still no...