Question

When I am passing datetime parameter in OPENROWSET query, I get the following error:

Conversion failed when converting date and/or time from character string

SELECT * FROM OPENROWSET('SQLNCLI',
    'SERVER=localhost;UID=test;PWD=test', 
    'set FMTONLY OFF exec testdatabase.dbo.Proc_Salaryslip_PF '','','','',''5112'','','','','',''8'',''2012'','','',''0'',''1'',A,20120401,20130301,''Y'',''Y'','',A,admin,0,N,'',''18'' ') 

Please suggest some solution, my project is depending upon your answer.

Was it helpful?

Solution

These looks suspicious 20120401,20130301. If they are passed to a datetime parameter you will get:

Error converting data type int to datetime.

Since you pass them as integer instead of string literal. To fix that you have to quote them as strings.

But since that is not the error you get you are passing another parameter as a string to a datetime parameter.

Here is the parameter list you use, one row for each parameter. Check against the declaration of your procedure.

exec testdatabase.dbo.Proc_Salaryslip_PF 
',',
',',
'5112',
',',
',',
'8',
'2012',
',',
'0',
'1',
A,
20120401,
20130301,
'Y',
'Y',
',A,admin,0,N,',
'18' 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top