0

I've this array of strings:

$qLastSS_T
2024-07-08 11:56:32
2024-08-08 12:56:32
2024-09-08 13:56:32
2024-10-08 13:56:32
2024-11-08 15:56:32
2024-12-08 16:56:32

and a SQL table like this:

table

Is it possible to insert the values of array in to the "LAST_SS_DATE" column in order to obtain a result like this:

TABLE 2

I'm not familiar with T-SQL and when LAST_SS_DATE has N/D as value, I'm using this syntax for the insert:

$GESQueryIN = "INSERT INTO Monitoraggio.dbo.IMGs_BKP (DATE,SERVER,SIDE,DAY,SUCCESS,FAILURE_REASON,SS_EXIST,LAST_SS_DATE,LAST_SS_EXIPIRE) VALUES ('$qDT_RunBKP','$_','$qSide','$qDayOfBKP','$qSucces','$qFailRea','$qSS_Exist','$qLastSS_T','$qLastSS_E');"

and I run it with the Invoke-SqlCmd cmdlet

4
  • You can join the strings using Concat, but you need a return at the end of each string : learn.microsoft.com/en-us/sql/t-sql/functions/… Commented Jul 12, 2024 at 17:47
  • 'one','two','three' -join "`n" maybe Commented Jul 12, 2024 at 18:07
  • 1
    Just a side note. T-SQL / SQL Server does not support any sort of array/list data types. So your only option in the database would be to store the datetime values as strings. Like a CSV, JSON, XML, etc. If you don't have control over the schema, and this is how it's handled there, I understand. But if you do have control...then I would highly recommend storing these values in another table and use some sort of lookup key back in Monitoraggio.dbo.IMGs_BKP. Storing the datetime values as a list of strings within SQL Server is not a good practice. Commented Jul 13, 2024 at 5:28
  • LAST_SS_DATE is defined how as a column? Seems weird to add more that one date time value into a single column as a string. Commented Jul 13, 2024 at 18:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.