January 17, 2014 at 11:46 am
Hello,
I have a request to build a random data generator for Manufacturing Inventory Checks.
Everyday, the requester would like a list of 20 locations picked randomly from a DB for inventory checks.
I only have a few columns to consider;
1. Site Reference (ex. ABC)
2. Warehouse (Ex. Minn)
3. Location (Ex. C123)
So when the report gets generated, it would list the 20 randomly chosen locations for that day.
Any thoughts or ideas would be greatly appreciated.
Thanks
January 17, 2014 at 11:50 am
mbrady5 (1/17/2014)
Hello,I have a request to build a random data generator for Manufacturing Inventory Checks.
Everyday, the requester would like a list of 20 locations picked randomly from a DB for inventory checks.
I only have a few columns to consider;
1. Site Reference (ex. ABC)
2. Warehouse (Ex. Minn)
3. Location (Ex. C123)
So when the report gets generated, it would list the 20 randomly chosen locations for that day.
Any thoughts or ideas would be greatly appreciated.
Thanks
Pretty sparse on details here. The easiest way to get 20 random rows from Location is to just use NEWID() in an order by clause.
select top 20 * --You would use real column names here
from Location
order by NEWID()
You will get a different resultset every time you execute this.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
January 17, 2014 at 1:41 pm
Thanks a lot Sean. This works perfect for the requirement.
January 20, 2014 at 7:13 am
mbrady5 (1/17/2014)
Thanks a lot Sean. This works perfect for the requirement.
Glad that worked for you and thanks for letting me know.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply