Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Update Table with get-date


Update Table with get-date

Author
Message
zero1de
zero1de
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
Points: 6 Visits: 99
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: (Smile [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Lowell
Lowell
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14959 Visits: 38975
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

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Jeff Moden
Jeff Moden
SSC-Forever
SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)

Group: General Forum Members
Points: 45119 Visits: 39918
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.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is not.
Just because you can do something in PowerShell, doesnt mean you should. Wink

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
zero1de
zero1de
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
Points: 6 Visits: 99
Thx it's works.
zero1de
zero1de
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
Points: 6 Visits: 99
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 Smile
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search