sql - The conversion of a varchar data type to a datetime data type resulted in an out-of-range value using a script -
using following code getting error:
exception calling "fill" "1" argument(s): "the conversion of varchar data type datetime data type resulted in out-of-range value." @ c:\users\username\desktop\test.ps1:47 char:1 + $commandcompl.fill($dt7) | out-null + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : notspecified: (:) [], methodinvocationexception + fullyqualifiederrorid : sqlexception
$host.ui.rawui.buffersize = new-object management.automation.host.size (200, 25) $date = (get-date).tostring("yyyymmdd") clear $sqltablecomplia = 'abc' $sqlservercomplia = "123.123.123.123" $sqldbnamecomplia = "test" $usernamecomplia = "abc" $passwordcomplia = "pasword" $sqlserverlandesk = "cba\test1" $sqlconnectionlandesk = new-object system.data.sqlclient.sqlconnection $global:dt = new-object system.data.datatable $dr = "" $lona = "" $o = 0 $j = 0 $globalvuln , $globalnotvuln = 0 $global:dt7 = new-object system.data.datatable $sqlconnectioncomplia = new-object system.data.sqlclient.sqlconnection $sqlconnectioncomplia.connectionstring = "server=$sqlservercomplia; database=$sqldbnamecomplia;uid=$usernamecomplia; pwd=$passwordcomplia" $sqlconnectioncomplia.open() | out-null $querycompl = "select top 1 convert(datetime,left(ld_publishdate,10),103) r vulns order r desc" $commandcompl = new-object system.data.sqlclient.sqldataadapter ($querycompl, $sqlconnectioncomplia) $commandcompl.fill($dt7) | out-null
what doing wrong? how can solve this?
so problem here simple , problem following line
convert(datetime,left(ld_publishdate,10),103)
and style parameter mentioned '103' means trying convert british/french standard. british or french standard varchar value should in format of 'dd/mm/yy' other format fail.
for example following script fail same error getting
select convert(datetime,left('2015/09/21',10),103)
while pass swiftly
select convert(datetime,left('21/09/2015',10),103)
either solve or try appropriate value style. can find appropriate values here http://www.techonthenet.com/sql_server/functions/convert.php
hope helps.
Comments
Post a Comment