Error when using parameter in a query

rinxman

Board Regular
Joined
Mar 20, 2009
Messages
60
I have a spreadsheet with 2 tabs, each with its own query via ODBC connection. On one query it works fine with parameters. On the other, when I have a date hard coded it runs fine. When I change the code to a ? so it will prompt for a parameter, that is when I get the errors:

[Microsoft][ODBC SQL Server Driver] Syntax Error or access violation
[Microsoft][ODBC SQL Server Driver] Invalid Descriptor Index

I am not sure why one works and why the other doesn't. Please help.

The code for the failing query is:
select t.cal_date
,a.agent_name
,a.Phone_Login
,t.dialed_nbr
from opscall.dbo.cc_gen_transfers_dialed t
inner join OpsDataD.dbo.resource_master rm
on rm.network_id = t.transf_empid
join opscall.dbo.cc_single_source_agent a
on rm.resource_id = a.resource_id
and t.cal_date = a.date
where t.cal_date between ? and ?
and rm.location_nbr in (22)
and rm.end_date > getdate()
group by t.cal_date
,a.agent_name
,a.Phone_Login
,t.dialed_nbr
order by 1,2,4


The code for the working query is:
select t.cal_date,101)
,a.agent_name
,a.Phone_Login
,a.in_calls_handled as inb_calls
,sum(t.transfers) as transfers
from opscall.dbo.tempe_agent_transfers t
inner join OpsDataD.dbo.resource_master rm
on rm.network_id = t.network_id
join opscall.dbo.cc_single_source_agent a
on rm.resource_id = a.resource_id
and t.cal_date = a.date
where t.cal_date between ? and ?
and rm.end_date > getdate()
group by t.cal_date
,a.agent_name
,a.Phone_Login
,a.in_calls_handled
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Forum statistics

Threads
1,215,008
Messages
6,122,672
Members
449,091
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top