Forum Discussion
noodles1030
Apr 09, 2024Copper Contributor
The given value of type String from the data source cannot be converted to type nvarchar of the spec
Hi, I am creating a date variable and attempting to write that variable to a SQL table. In my PS script, I do this: $DateTime = $((Get-Date).ToString('yyyy-MM-dd-hh_mm_ss')) I have tried set...
olafhelper
Apr 10, 2024Bronze Contributor
$DateTime = $((Get-Date).ToString('yyyy-MM-dd-hh_mm_ss'))
noodles1030 , your format string is wrong, no culture setting supports underscores in the time portion, see Standard date and time format strings - .NET | Microsoft Learn
noodles1030
Apr 11, 2024Copper Contributor
olafhelper - I have changed that previously and it still will not work. If it is just a string and not datetime, why would that matter?
It is interesting - I can do the same thing with the same PowerShell script and write to a different table and it works. The column in the 2nd table is also nvarchar... any idea on that?
Thanks!
- olafhelperApr 12, 2024Bronze ContributorCan't say, you just posted one line of code, I don't know, what you do with the result in the rest.
- noodles1030Apr 29, 2024Copper Contributor
Thanks for your help - I just ended up using nvarchar to solve this. However, I think it could have been a different column having the issue than the one I was debugging. I never found a way to determine which other date columns might have been the problem. Please let me know if you know of a way to debug a bulk copy ...
Thanks very much.