Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Update Table with get-date Expand / Collapse
Author
Message
Posted Monday, July 1, 2013 8:48 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, December 15, 2014 12:42 AM
Points: 6, Visits: 64
Hi,

i want to update my table Field Date_Import=get-date -f (without time)
TBL_Import
[Count_Import] int NULL,
[Count_Fault] int NULL,
[Date_Import] date NULL

$Command = $Connection.CreateCommand()
$Count_Fault = $directory_file_count
$Date_used = get-date
$Command.CommandText ="update TBL_IMPORT set Count_Fault=$Count_Import where $Date_Import=$date_used"
$Command.ExecuteNonQuery()
$Connection.Close()

What is wrong in my code ? the Problem is on where clause ..

Many THX

I get this Msg:
Ausnahme beim Aufrufen von "ExecuteNonQuery" mit 0 Argument(en): "Incorrect syntax near '16'."
Bei D:\Skripte\Count_Fault.ps1:54 Zeichen:27
+ $Command.ExecuteNonQuery <<<< ()
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Post #1469097
Posted Monday, July 1, 2013 9:30 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 2:35 PM
Points: 12,962, Visits: 32,498
i'm guessing since you are using powershell to substitute values, the date parameter must be in single quotes;

also, it looks like $Date_Import would get substituted too, which makes an invalid query?

i think it's $Date_Import gets substituted with empty string, plus maybe the date issue? :
value = 07/01/2013
vs
value = '07/01/2013'


not sure why the value 16 is an error, though? is it really this is the problem?
Count_Fault=$Count_Import


$Command.CommandText ="update TBL_IMPORT set Count_Fault=$Count_Import where $Date_Import=$date_used"

i think it needs to be this: the change is sublte:
$Command.CommandText ="update TBL_IMPORT set Count_Fault=$Count_Import where Date_Import='$date_used'"



Lowell

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1469119
Posted Monday, July 1, 2013 6:11 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 7:27 AM
Points: 35,769, Visits: 32,437
Why are we doing this in PowerShell?

--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1469248
Posted Tuesday, July 2, 2013 2:52 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, December 15, 2014 12:42 AM
Points: 6, Visits: 64
Thx it's works.
Post #1469348
Posted Tuesday, July 2, 2013 2:53 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, December 15, 2014 12:42 AM
Points: 6, Visits: 64
Lowell (7/1/2013)
i'm guessing since you are using powershell to substitute values, the date parameter must be in single quotes;

also, it looks like $Date_Import would get substituted too, which makes an invalid query?

i think it's $Date_Import gets substituted with empty string, plus maybe the date issue? :
value = 07/01/2013
vs
value = '07/01/2013'


not sure why the value 16 is an error, though? is it really this is the problem?
Count_Fault=$Count_Import


$Command.CommandText ="update TBL_IMPORT set Count_Fault=$Count_Import where $Date_Import=$date_used"

i think it needs to be this: the change is sublte:
$Command.CommandText ="update TBL_IMPORT set Count_Fault=$Count_Import where Date_Import='$date_used'"





Thx it works fine :)
Post #1469349
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse