- 0
[SQL] How to loop through a list of values?
-
Recently Browsing 0 members
- No registered users viewing this page.
-
Posts
-
By Ccl Ncc · Posted
Exactly what I was thinking. All of a sudden in span of a month multiple CEO's from scam altman to this clown has had sudden change of heart does not seem organic change lol -
By zikalify · Posted
Microsoft releases Visual Studio Code 1.124 with smarter autonomous AI agents by Paul Hill Microsoft has just released Visual Studio Code 1.124 with a focus on faster agent workflows and improved agent autonomy. Microsoft outlined the following features as the key items in this update: Autopilot: Autopilot, enabled by default, is now smarter to determine when a task is truly done. Background sessions: Quickly send a request in the background and keep composing the next session. Session navigation: Search, jump, and step through agent sessions with the keyboard. Browser history: Revisit and search pages you've already opened in the integrated browser. With VS Code 1.124, Microsoft has enabled Autopilot by default. For those that don’t know, Autopilot is a chat permission level that you can pick to give agents permission to take initiative and act autonomously, without needing explicit user approval for each action. Also related to Autopilot, Microsoft introduced Advanced Autopilot, which changes how Autopilot decides when to keep iterating and when to finish. This helps you get more complete results without manually monitoring loops. This feature works using a small utility model that reads a transcript of the chat and decides when the task is done. Another new feature in 1.124 is the Agents window, which lets you easily explore, iterate on, and review agent sessions across projects and machines. Previously, starting a new agent session meant waiting for it to load before you could compose the next one. With this update, sessions can be requested in the background. This VS Code update also brings session navigation updates to switch between them more quickly. The update also lets you reload or reopen the Agents window so that it no longer loses your layout, so you will land back where you left off. If you use the integrated browser in VS Code, you will notice that it now retains the history of visited pages. Suggestions will now show when typing in the URL bar and can be managed by using Ctrl+H within a browser tab. The browser now also lets you customize the toolbar more; just right-click on the toolbar area to the right of the URL input. Finally, the browser has faster agentic text entry. Another improvement is experimental enterprise-managed Copilot plugin policies that allow admins to centrally control which chat plugins and plugin marketplaces are available to developers. If you have VS Code installed, 1.124 should install automatically, or you'll get a prompt. If you don't have it installed, get it here. -
By Mockingbird · Posted
Ray-Tracing is the Radeon RX 9070 XT's biggest weakness. The Radeon RX 9070 XT might not be able to match in the GeForce RTX 5070 Ti in ray-tracing, but it can beat the GeForce RTX 5070, which is around the same price. -
By Shagath · Posted
I am also on latest experimental with possible insider flags on and aiming in settings for 26h1.. Also see just this wasted space. I do love "movable" small taskbar though but would love more if it had date next to it now just time. -
By margrave · Posted
Does not make it more readable for me though. The majority of your screenshot is just pitch black.
-
-
Recent Achievements
-
X-No-file earned a badge
First Post
-
johnjacobb40 earned a badge
One Month Later
-
Primer1st earned a badge
One Year In
-
JayZJay went up a rank
Experienced
-
Sir_Timbit earned a badge
Reacting Well
-
-
Popular Contributors
-
Tell a friend
Question
SirEvan
I'm working on a SQL query that needs to go and update a date in one table, with values from another table, if the values in the first table match a specified list. I wrote a Query already that can go through the entire table and update the dates, but now I've been given a select list that a customer wants updated, instead of the entire table. In .Net, I'd make an array and store the values in there and loop through that, but not sure if what I need in SQL is a WHILE loop, or if what I have below will work good enough?
I need to basically update values in the database When one of the values matches the "IN" clause I have...so for example, if you find Value 1, take it's date and put it in the matching date in another table for that UID, take the date for UID #2, do the same thing, etc.
Thanks in Advance:
/* SQL Script to go through UIDDetail table and take Accepted dates and fill in for */ /* Corresponding field in UIDMark Table for Mark Effective Date */ /* Version 0.1 by Evan Richardson - GSS Oct-29-2010 */ /* Tested so far against IGuides 3.5 SQL DB only!!! */ /* This is for General Dynamics IT IGuides only!!! */ /*Declare the variables we'll use for placeholders */ DECLARE @AcceptDate datetime DECLARE @AcceptID INT SET @AcceptID = ( SELECT [UIDDetail_ID] FROM [IGUIDES].[dbo].[UIDDetail] WHERE [UIDNbr] IN('D1R7S3PS7500-L100M-XA175-10013111', 'D1R7S3PS7500-L100M-XA175-10013159', 'D1R7S3PS7500-L100M-XA175-10013300', 'D1R7S3PS7500-L100M-XA175-10013451', 'D59951KVT417A-1UV-A09040057', 'D6703202-2799081-1BDB42C1', 'D6703202-2799237-1000013', 'D6703203-2802005-1FTX1329A0QM')) /* fill the Accepted Date and ID Variables */ SET @AcceptDate = (SELECT [AcceptDate] FROM [IGUIDES].[dbo].[UIDDetail] WHERE [UIDDetail_ID]=UIDNbr) SET @AcceptID = (SELECT [UIDDetail_ID] FROM [IGUIDES].[dbo].[UIDDetail] WHERE [UIDDetail_ID]=UIDNbr) /* Begin Updating the Effective Date in the UIDMark Table with the Value taken from the UIDDetail Table, using the UIDDetail_ID value as the control, since it's the linking value between the two tables */ IF @AcceptDate IS NOT NULL UPDATE [IGUIDES].[dbo].[UIDMark] SET [EffectiveDate] = @AcceptDate WHERE [UIDDetail_ID] = @AcceptID /* <--- That is the value we declared above */EDIT:
I think I might have figured it out, by declaring a table variable:
/* SQL Script to go through UIDDetail table and take Accepted dates and fill in for */ /* Corresponding field in UIDMark Table for Mark Effective Date */ /* Version 0.2 by Evan Richardson - GSS Oct-29-2010 */ /* Tested so far against IGuides 3.5 SQL DB only!!! */ /* This is for General Dynamics IT IGuides only!!! */ /*Declare the variables we'll use for placeholders */ DECLARE @AcceptDate datetime DECLARE @AcceptID INT DECLARE @UIDsToModify TABLE (UIDDetail_ID INT, AcceptDate datetime) DECLARE @counter INT DECLARE @FirstRow INT DECLARE @EndRow INT INSERT INTO @UIDsToModify SELECT [UIDDetail_ID], [AcceptDate] FROM [IGUIDES].[dbo].[UIDDetail] WHERE [UIDNbr] IN( 'D1R7S3PS7500-L100M-XA175-10013111', 'D1R7S3PS7500-L100M-XA175-10013159', 'D1R7S3PS7500-L100M-XA175-10013300', 'D1R7S3PS7500-L100M-XA175-10013451', 'D59951KVT417A-1UV-A09040057', 'D6703202-2799081-1BDB42C1', 'D6703202-2799237-1000013', 'D6703203-2802005-1FTX1329A0QM') SET @FirstRow = (SELECT MIN(UIDDetail_ID) FROM @UIDsToModify) SET @EndRow = (SELECT MAX(UIDDetail_ID) FROM @UIDsToModify) SET @counter = @FirstRow-1 /* Begin Looping through the Counter variable for each row in the table until we hit the end */ WHILE @counter <= @EndRow BEGIN /* Start incrementing the counter */ SET @counter = @counter+1 /* fill the Accepted Date and ID Variables */ SET @AcceptDate = (SELECT [AcceptDate] FROM @UIDsToModify WHERE [UIDDetail_ID]=@counter) SET @AcceptID = (SELECT [UIDDetail_ID] FROM @UIDsToModify WHERE [UIDDetail_ID]=@counter) /* Begin Updating the Effective Date in the UIDMark Table with the Value taken from the UIDDetail Table, using the UIDDetail_ID value as the control, since it's the linking value between the two tables */ IF @AcceptDate IS NOT NULL UPDATE [IGUIDES].[dbo].[UIDMark] SET [EffectiveDate] = @AcceptDate WHERE [UIDDetail_ID] = @AcceptID /* <--- That is the value we declared above */ ENDLink to comment
https://www.neowin.net/forum/topic/949544-sql-how-to-loop-through-a-list-of-values/Share on other sites
10 answers to this question
Recommended Posts