Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - select from database and own parameter

Reply
 
Old 03-02-2009   #1 (permalink)
esska


 
 

select from database and own parameter

Hi,
I've huge problem with one thing. I need to create select in oracle
where one comparison will include my own parameter.
Here is example:

sql = "select to_char(oradatetime,'rrrr-mm-dd HH24:MI:SS') oratime
from table where oratime >= MYPARAMETER"


MYPARAMETER is date type - conversion the same like oradatetime
MYPARAMETER = date & " " & time

MyStrDate = CStr(MYPARAMETER )

If I use:
sql = "select to_char(oradatetime,'rrrr/mm/dd HH24:MI:SS') oratime
from table where oratime >= " & MyStrDate

I got error that:
Microsoft OLE DB
Provider for ODBC Drivers: [Microsoft][ODBC driver for Oracle][Oracle]
ORA-00933
: SQL command not properly ended

Does anybody know how to avoid this error
I've tried join, replace, chr(34) - nothing work when I try to use sql
connection I got this error.

Regards,
esska


My System SpecsSystem Spec
Old 03-02-2009   #2 (permalink)
Bob Barrows


 
 

Re: select from database and own parameter

esska wrote:
Quote:

> Hi,
> I've huge problem with one thing. I need to create select in oracle
> where one comparison will include my own parameter.
> Here is example:
>
> sql = "select to_char(oradatetime,'rrrr-mm-dd HH24:MI:SS') oratime
> from table where oratime >= MYPARAMETER"
>
>
> MYPARAMETER is date type - conversion the same like oradatetime
> MYPARAMETER = date & " " & time
Do you mean:
MYPARAMETER = Now()
?
Quote:

>
> MyStrDate = CStr(MYPARAMETER )
>
> If I use:
> sql = "select to_char(oradatetime,'rrrr/mm/dd HH24:MI:SS') oratime
> from table where oratime >= " & MyStrDate
>
> I got error that:
> Microsoft OLE DB
> Provider for ODBC Drivers: [Microsoft][ODBC driver for Oracle][Oracle]
> ORA-00933
Quote:

>> SQL command not properly ended
>
> Does anybody know how to avoid this error
> I've tried join, replace, chr(34) - nothing work when I try to use sql
> connection I got this error.
>
Use a parameter token:

sql = "select to_char(oradatetime,'rrrr/mm/dd HH24:MI:SS') " & _
"oratime from table where oratime >= ?"

Use a command object to pass the value into the statement:

set cmd=createobject("adodb.command")
cmd.commandtype=1 '1=adCmdText
cmd.commandtext=sql
set cmd.activeconnection = yourcommandobject
set rs = cmd.execute(,CDate(MYPARAMETER))


--
Microsoft MVP - ASP/ASP.NET - 2004-2007
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


My System SpecsSystem Spec
Old 03-02-2009   #3 (permalink)
gimme_this_gimme_that


 
 

Re: select from database and own parameter

The error message you're getting says that your SQL command isn't
properly ended.

That means you need single quotes around the date.

sql = "select to_char(oradatetime,'rrrr/mm/dd HH24:MI:SS') oratime
from table where oratime >= '" & MyStrDate & "'"
My System SpecsSystem Spec
Old 03-03-2009   #4 (permalink)
esska


 
 

Re: select from database and own parameter

Hi,
Thank you for replying.

The problem was with sql, it shoud be something like this:

sql = "select to_char(oradatetime,'rrrr/mm/dd HH24:MI:SS') from table
where oradatetime>= (' " & MyStrDate & "','rrrr/mm/dd HH24:MI:SS')".

I use this to execute command: oRs.open sql, oConn
which is similar to executhing made by Bob.

Thank you for help.

Regards,
esska
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Using multiple Parameter sets for a Parameter PowerShell
Configuration parameter in SQL database .NET General
Works database 2007 and Office database 2003 .NET General
How to best control parameter attributes and parameter parsing in your own scripts? PowerShell
Suggestion: new parameter for Select-Object: "-Which <position> PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46