D
Deleted member 143609
Guest
Total newbie here so hello to all. Have started using Access/SQL in work so hoping learn a lot from the Access community! I’m reasonably comfortable with Powershell and C++ but that’s as far as my experience goes unfortunately so I’m going to dive right in the deep end here with a big question:
I’ve created two small queries (sad how long it actually took me..) and while they run well and output a value, I’m hoping I can combine the two to run as one. The reason being is because I’m doing all of this through Powershell (very convoluted but the set up in work is bizarre) and rather than running heaps of different queries, I could reduce the number just by combining the queries that are used, particularly the ones that involve the same tables. Here’s an example:
This just selects the highest node number (Not all the values in the column are the same format so the condition is that ‘Max Node’ 14 digits long, starts with 900101 and doesn’t have a ‘-‘ sign.).
This query updates every value that has the parameters mentioned above with the [Max Node] from the first query. Obviously I want it to increment by 1 for each node, starting with the max mode number. I have two issues though: The second query replaces every value with just the max node number and doesn’t increment by 1 for each one and secondly, I can’t seem to combine the two queries. I’ve tried UNION, UNION ALL and INNER JOIN but unfortunately nothing seems to be working.
Is this type of combination just not possible in SQL? I apologise for the long post (especially since it’s my first!) but I’m just trying to kill two queries with one stone. Thanks!
I’ve created two small queries (sad how long it actually took me..) and while they run well and output a value, I’m hoping I can combine the two to run as one. The reason being is because I’m doing all of this through Powershell (very convoluted but the set up in work is bizarre) and rather than running heaps of different queries, I could reduce the number just by combining the queries that are used, particularly the ones that involve the same tables. Here’s an example:
Code:
SELECT TOP 1 Max(Round(Val([NodeNameIdMap]![StringVal]),0))+1 AS [Max Node]
FROM NodeNameIdMap
WHERE len([NodeNameIdMap]![StringVal]) = 14
AND
LEFT(NodeNameIdMap.[StringVal], 6) = '900101'
AND
(NodeNameIdMap.StringVal) NOT LIKE '*[-]*'
This just selects the highest node number (Not all the values in the column are the same format so the condition is that ‘Max Node’ 14 digits long, starts with 900101 and doesn’t have a ‘-‘ sign.).
Code:
UPDATE NodeNameIdMap
SET NodeNameIdMap.[StringVal] = [Max Node] +1
WHERE LEFT(NodeNameIdMap.[StringVal], 6) <> '900101'
OR ((NodeNameIdMap.StringVal) Like '*[-]*')
OR ((Len([StringVal]))<'14')
OR ((Len([StringVal]))>'14');
This query updates every value that has the parameters mentioned above with the [Max Node] from the first query. Obviously I want it to increment by 1 for each node, starting with the max mode number. I have two issues though: The second query replaces every value with just the max node number and doesn’t increment by 1 for each one and secondly, I can’t seem to combine the two queries. I’ve tried UNION, UNION ALL and INNER JOIN but unfortunately nothing seems to be working.
Is this type of combination just not possible in SQL? I apologise for the long post (especially since it’s my first!) but I’m just trying to kill two queries with one stone. Thanks!