I am trying to do something like
DECLARE @ID int = CHANGEME,
@StartDate datetime = '2023-09-02 04:00',
@FinishDate datetime = '2023-09-03 04:00'
But this only lets me run this report per id, I have a list of IDs from another table that i can pull by a query
select id
form table
where tablename like '$tryme$'
So is there a way that I can run the report per ID again and again until we've run the list finished?
I saw that this is the way to write multiple/array in the statement
DECLARE @SITEIDS TABLE(siteid int)
Insert into @SITEIDS
values ('R00013'), ('R00028')
but this looks like it's hard coded ids.
I'm trying to get a report with
DECLARE @ID int = 1,
DECLARE @ID int = 12,
DECLARE @ID int = 123,
2条答案
按热度按时间xvw2m8pv1#
Something like the following should allow you to do exactly what you are asking.
You put the MIN(id) into your @id variable, process the report for that value, then grab the next MIN(id) that's greater than the one you just processed, and keep looping until no more id value is found.
cgh8pdjw2#