- 0
[SQL] How to loop through a list of values?
-
Recently Browsing 0 members
- No registered users viewing this page.
-
Posts
-
By cleverclogs · Posted
I haven't paid for windows since windows 8. So I guess I would be happy to pay for a new version if it meant seeing fewer adverts (none) or product pushes. But that applies to _any_ service or OS. -
By cork1958 · Posted
Edit: Oops! Wrong topic! :( -
By TarasBuria · Posted
Save 35% on Sony's SS-CS5M2 3-way high-res bookshelf speakers by Taras Buria Sony is currently offering a big discount on its SS-CS5M2 bookshelf speaker, saving you 35% on a set of high-quality audio equipment. The SS-CS5M2 is a passive 3-way bookshelf speaker with a 5.12-inch woofer, a 25 mm soft-dome tweeter, and a 19 mm super tweeter. This design allows different drivers to handle different parts of the sound spectrum for a clearer, more detailed audio when watching movies or listening to music. The compact cabinet size allows you to place these speakers on shelves, desks, or stands, making them a practical choice for apartments, bedrooms, and small living rooms. Despite its compact size, the SS-CS5M2 delivers up to 100 W of power. Note that since the speakers are passive, you will need an amplifier to drive them. However, if you do, you can use them for high-resolution music, thanks to a claimed frequency response of 53 Hz - 50 kHz. It is able to extend so far high in the spectrum as a result of those super tweeters. While they will work with most amplifiers and AV receivers, Sony says this pair is a perfect match for its AV receivers, such as STRDH190, 590, 790, or 1000. Sony CS Bookshelf Speakers SS-CS5M2 3-Way 3-Driver Hi-res - $178 | 36% off on Amazon US This Amazon deal is US-specific and not available in other regions unless specified. This is a first-party seller link (at the time of article publishing); ensure that you also purchase from a first-party seller link only. If you don't like it or want to look at more options, check out the previous deals that we have covered, OR you can also visit Amazon US deals page. Get Prime (SNAP), Prime Video, Audible Plus or Kindle / Music Unlimited. Free for 30 days. As an Amazon Associate, we earn from qualifying purchases. -
By AltecXP · Posted
So they somehow expect Apple to easily make it so that if I install say DeepSeek that DS can then handle all the tasks that Siri would be doing while integrated in the OS? That sounds like just rediculous. -
By Mockingbird · Posted
For ray-tracing, the Radeon RX 9070 XT is better than the GeForce RTX 5070, but worse than the GeForce RTX 5070 Ti The Radeon RX 9070 XT is similar to the GeForce RTX 5070 Ti in rasterization Both AMD and NVIDIA have had serious issues with drivers in the past, so I can't say that one is better or worse than the other. Yes. AMD has better support Linux than does NVIDIA. Use Display Driver Uninstaller (DDU) to uninstall NVIDIA's drivers before installing AMD's drivers. That's up to you. Supplies of memory is unpredictable because AI using up a lot of memory. As a result, there is a lot of volatility in video card prices.
-
-
Recent Achievements
-
lamborghiniv10 went up a rank
Rookie
-
pinnclepd earned a badge
One Month Later
-
X-No-file earned a badge
First Post
-
johnjacobb40 earned a badge
One Month Later
-
Primer1st earned a badge
One Year In
-
-
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