0

I am trying to find a way to randomize invoice numbers in a SQL Server query to just see 15 random invoices, is there a way to do this?

select 
f.Facility
,v.Vendor_Name
,d.Date as 'Posting_Date' --,Trans_Date_Skey --post
,Trans_No
,Invoice_No
,Invoice_Date as 'Service_Date' --service
,Charge_Amount
,Apply_Amount
,Entry_Date
from dw.dbo.fctAPCharges c
left join dw.dbo.dimfacility f on f.Facility_Skey = c.Facility_Skey
left join dw.dbo.dimVendor v on v.Vendor_Skey = c.Vendor_Skey
left join dw.dbo.dimDate d on d.DateKey = c.Trans_Date_Skey
mustaccio
  • 25,896
  • 22
  • 57
  • 72

1 Answers1

1

You mean you want to randomly select 15 rows ?

use TOP with ORDER BY NEWID()

SELECT TOP (15) 
       . . . 
ORDER BY NEWID()
Squirrel
  • 538
  • 2
  • 9
  • I want to take all the invoices that are in the system and randomly select 15 of them – Sammy Rhine Sep 05 '21 at 14:24
  • So does the query meets your requirement ? – Squirrel Sep 06 '21 at 01:02
  • no I am also trying to specify that its from the previous week for each week moving forward it will always come up with 15 random for the previous week – Sammy Rhine Sep 06 '21 at 14:53
  • That requirement was not in your initial question. It is better you start a new question over in StackOverflow.com. State your requirement clearly, show your current query, include sample data and expected result. Avoid posting image, use formatted text instead – Squirrel Sep 07 '21 at 00:53