passing date variable to sp

M

mirza i

in asp i have this line:
.....
Set paramsx = cmdUpdatex.CreateParameter ("@invdate", addate, adParamInput,
50, invdate)
cmdUpdatex.Parameters.Append paramsx
...
(the invdate value is a dd/mm/yyyy date)


AND in sql server 2000 sp i have:

....
@invdate nvarchar(100)= null,
....
insert into inv
(
invdate,
)
values
(
@invdate,
)

when i run this it does not work...
so i run profiler and extracted the problem line.
in query analyser it gives me the:
Syntax error converting character string to smalldatetime data type.


what do you guys think is the problem?
 
B

Bob Barrows [MVP]

mirza said:
in asp i have this line:
....
Set paramsx = cmdUpdatex.CreateParameter ("@invdate", addate,
adParamInput, 50, invdate)
cmdUpdatex.Parameters.Append paramsx
..
(the invdate value is a dd/mm/yyyy date)


AND in sql server 2000 sp i have:

...
@invdate nvarchar(100)= null,
...
insert into inv
(
invdate,
)
values
(
@invdate,
)

when i run this it does not work...
so i run profiler and extracted the problem line.
in query analyser it gives me the:
Syntax error converting character string to smalldatetime data type.


what do you guys think is the problem?

Date format.
http://www.aspfaq.com/show.asp?id=2040

Bob Barrows
 

¶Ë°­¾ÆÁö

In my case

Set paramsx = cmdUpdatex.CreateParameter ("@invdate", addate, adParamInput,
50, invdate)

=>
Set paramsx = cmdUpdatex.CreateParameter ("@invdate", advarchar,
adParamInput,
20, invdate)

and in sql sp you have to change
@invdate varchar(20) to convert(smalldatetime, @invdate)
 
M

mirza i

i have tried everything (lost 5hrs and gained 1000 gray hairs)
tomorrow i'll try your suggestion.

thanks
 
C

CJM

mirza i said:
i have tried everything (lost 5hrs and gained 1000 gray hairs)
tomorrow i'll try your suggestion.

thanks

I think you'll find the link Bob posted has the answers...

In simple, use the ISO-style Date format: e.g. 20041210 (ISO date format
is actually 2004-12-10)

Chris
 
M

mirza i

ok, figured it out.

i have tried everything from changing dateformat in datab to passing dates
instead of varchar and to my great happiness nothing worked.


in datab:
invdate is datetime,8

from asp:
Set paramsx = cmdUpdatex.CreateParameter ("@invdate", adVarChar,
adParamInput, 50, invdate) cmdUpdatex.Parameters.Append paramsx

and in sql server:
(in @ declares)
@invdate nvarchar(100)= NULL,
and
(in prog)
SELECT @invdate = CONVERT(datetime, @invdate, 103)
....

by the way, this was strange one since i don't think i have changed anything
in prog, sproc or in database and yet the app did not work anymore...
so,
lessons learned: as always figuring out what the problem is in a sproc is a
******* nightmare...
in future i will always use yyyymmdd, this app in now too big for that kind
of change.

many thanks for all that have replied :)

regards

mirza
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top