I've got a SQL query for inserting data into a table consisting of values for StorageRowNo
and StorageID
. The goal is to repeat this query a specified number of times with StorageRowNo
increasing by 1 every time the query is repeated. Any input would be greatly appreciated!
INSERT [dbo].[StorageRow]
SELECT StorageRowNo, StorageID
FROM (VALUES (1, 2)) V (StorageRowNo, StorageID)
WHERE NOT EXISTS (SELECT 1
FROM [dbo].[StorageRow] C
WHERE C.StorageRowNo = V.StorageRowNo
AND C.StorageID = V.StorageID);
Expected output would be something like this if the specified number were 3.
| StorageRowNo | StorageID |
| ------------ | ------------ |
| 1 | 2 |
| 2 | 2 |
| 3 | 2 |
1条答案
按热度按时间uelo1irk1#
use straight sql if you can