passing date value as arg to script 
Author Message
 passing date value as arg to script

I've got a script to which I need to pass arguments.  I've never done
this before and I'm getting an error message.  Can you tell me what I
am doing wrong please?

The script will be called from a SQL Server job.  I'm testing now from
a command line prompt with the following line:

cscript \\HQImpact\mktData\MSSQL7\MOdifiers.vbs "2/19/03", "2/22/03"

There is an error message being returned:
"Microsoft OLE DB Provider for SQL Server: The conversion of a char
data type to a datetime data type resulted in an out-of-range datetime
value."

The code in the script is:

    BDay1=wscript.arguments(0)
    BDay2=wscript.arguments(1)

sISql = "select distinct m.parsalesdetailid, m.parsaleshdrid,
m.unitnumber," & _
    "d.positem, d.BusinessDay, m.posModifier, m.Condiment from
parsalesdetailmodifier m left join " & _
    "parsalesdetail d on m.parsalesdetailid = d.parsalesdetailid and "
& _
    "m.parsaleshdrid = d.parsaleshdrid and d.unitnumber = m.unitnumber
" & _
    "where m.unitnumber = 31 and m.posModifier is not null and
d.businessday between '" & _
    BDay1 & "' and '" & BDay2 & "' order by d.businessday, " & _
    "m.parsalesdetailid, m.parsaleshdrid, m.unitnumber, m.posmodifier,
m.condiment"

    rsImpact.CursorLocation = 1
    rsImpact.Open sISql, cnImpact, 2, 3

This works just fine when I set BDay1 = "2/19/03" and BDay2 =
"2/23/03" directly.

What is the correct way to pass a date value to a vbs script?

Thanks,
Jennifer



Wed, 17 Aug 2005 00:57:35 GMT  
 passing date value as arg to script
Hi,

I think the parameters pass OK. If hard coding
BDay1="2/19/03"
works, then the SQL syntax must expect a character string.
It might be interpreting the date as a formula. Perhaps
force it to be a string with:

Bday1 = CStr(wscript.Arguments(0))

or

BDay1 = "" & wscript.arguments(0) & ""

You may have to use this in the SQL statement:

d.businessday between '" & _
    CStr(BDay1) & "' and '" & CStr(BDay2) & "'

Richard

Quote:
-----Original Message-----
>I've got a script to which I need to pass arguments.  
I've never done
>this before and I'm getting an error message.  Can you
tell me what I
>am doing wrong please?

>The script will be called from a SQL Server job.  I'm
testing now from
>a command line prompt with the following line:

>cscript \\HQImpact\mktData\MSSQL7

\MOdifiers.vbs "2/19/03", "2/22/03"
Quote:

>There is an error message being returned:
>"Microsoft OLE DB Provider for SQL Server: The conversion
of a char
>data type to a datetime data type resulted in an out-of-
range datetime
>value."

>The code in the script is:

>    BDay1=wscript.arguments(0)
>    BDay2=wscript.arguments(1)

>sISql = "select distinct m.parsalesdetailid,
m.parsaleshdrid,
>m.unitnumber," & _
>    "d.positem, d.BusinessDay, m.posModifier, m.Condiment
from
>parsalesdetailmodifier m left join " & _
>    "parsalesdetail d on m.parsalesdetailid =

d.parsalesdetailid and "
Quote:
>& _
>    "m.parsaleshdrid = d.parsaleshdrid and d.unitnumber =
m.unitnumber
>" & _
>    "where m.unitnumber = 31 and m.posModifier is not
null and
>d.businessday between '" & _
>    BDay1 & "' and '" & BDay2 & "' order by

d.businessday, " & _

- Show quoted text -

Quote:
>    "m.parsalesdetailid, m.parsaleshdrid, m.unitnumber,
m.posmodifier,
>m.condiment"

>    rsImpact.CursorLocation = 1
>    rsImpact.Open sISql, cnImpact, 2, 3

>This works just fine when I set BDay1 = "2/19/03" and
BDay2 =
>"2/23/03" directly.

>What is the correct way to pass a date value to a vbs
script?

>Thanks,
>Jennifer
>.



Wed, 17 Aug 2005 03:16:22 GMT  
 passing date value as arg to script

Thanks for replying.  I finally figured out what I was doing wrong.  I
should have been pass the parameters without quotes around them and
without the comma between the parameters.  :)  I'm certainly not used to
command lines!

Thanks!
Jennifer

cscript Modifiers.vbs 1/1/03 1/10/03

Now if only I can figure out how to put the dates into variables with
dos....

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Wed, 17 Aug 2005 03:31:34 GMT  
 passing date value as arg to script

Quote:
> Now if only I can figure out how to put the dates into variables with
> dos....

What DOS, specifically?  If you're on WinNT/2K/XP this becomes a rather
simple task.  If you're on Win9x/ME it's harder, but still do-able.  Post
back with specifics and I or someone else here will help.


Wed, 17 Aug 2005 03:46:42 GMT  
 passing date value as arg to script

I re-read your original post.  You're obviously running NT/2K if you've got
SQL server going.

This will set 4 temp variables with the date information in various formats:

for /f "tokens=1,2,3 delims=/" %%a in ('date /t') do set tmpday=%%a &set
tmpmonth=%%b&set tmpyear=%%c
REM The statement above left %TMPDAY% with the text weekday in it.
REM Fix that up with the line below.
for /f "tokens=1,2 delims= " %%a in ("%tmpday%") do set tmpday=%%b
REM Set the variable tmpfulldate with the current date
for /f "tokens=1,2 delims= " %%a in ('date /t') do set tmpfulldate=%%b
set tmp

Watch for line wrap, the batch file is 8 lines total.



Wed, 17 Aug 2005 03:58:08 GMT  
 passing date value as arg to script
Well...it turns out that it's not necessary after all for what I'm
doing, but it would still be nice to know.

I'm running Windows 2000.  How do I create and set a variable in a batch
file?

For example, if I wanted to assign a date to a variable in VB, it would
be like this:

DIM BeginDateTime as String
BeginDateTime = Format(Date - 4, "MM/DD/YY") & " 3:00:00 pm"
This would give me "02/24/03 3:00:00 PM".

or I could do it like this:

DIM BegDateTime as Date
BegDateTime = Date - 4
This would give me "2/24/2003"

How would I accomplish this in a batch file?

Thanks for the help!

Jennifer

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Wed, 17 Aug 2005 04:01:16 GMT  
 passing date value as arg to script

Quote:
> I'm running Windows 2000.  How do I create and set a variable in a
> batch file?



Fri, 19 Aug 2005 11:35:00 GMT  
 passing date value as arg to script
Sorry for the other post, slapped CTRL-Enter by accident!

I'm assuming you sent this before my other post showed up on your news
server.  If not, let me know and I'll post the details.



Fri, 19 Aug 2005 11:35:41 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Passing Date values

2. Passing Multiple arg to a stored proc

3. passing arg by reference, very wierd problem

4. pass form arg to wsh shell exe ?

5. VC++ and VBS: returning value by ref in arg list

6. Passing value from Server script to client script.

7. How can pass a value from Vb script to java script

8. Passing arg to query driving a report

9. ShellExecute - passing a command line arg

10. => Pass Me as arg to subproceedure

11. pass arg to class_initialize

12. passing array to ParamArray arg?

 

 
Powered by phpBB® Forum Software