G12Consult
Programmer
Hi,
I am trying to import data from SQL Server into Excel.
I have setup the data connection etc and using a SQL statement to bring in the data.
In the SQL script I have two dates (which need to be parameters, dates which can be selected in Excel)
If I use specific dates in the WHERE clause such as '20162805' then I do not get an error.
If I replace with a ? for an excel parameter I am getting an error </code>microsoft odbc sql server driver sql server invalid column name</code>
My sql statement is below:
So the error is on the bottom line -
Any ideas please?
I am trying to import data from SQL Server into Excel.
I have setup the data connection etc and using a SQL statement to bring in the data.
In the SQL script I have two dates (which need to be parameters, dates which can be selected in Excel)
If I use specific dates in the WHERE clause such as '20162805' then I do not get an error.
If I replace with a ? for an excel parameter I am getting an error </code>microsoft odbc sql server driver sql server invalid column name</code>
My sql statement is below:
Code:
SELECT
occ.[EMPLOYEE_NO]
,occ.[JOB_NO]
,E.PREFERRED_NAME+' '+E.SURNAME AS EMPLOYEE_NAME
,T.TEAM_CODE
,T.TEAM_ALIAS
,T.TEAM_DESC
,CASE WHEN T.PRAC_GRP_NAME='Other' THEN 'Business Services' ELSE T.PRAC_GRP_NAME END AS PRAC_GRP_NAME
,O.OFFICE_DESC
,occ.[OCCUP_POS_TITLE]
,occ.PORTION_START AS PORTION_START
,occ.PORTION_END AS PORTION_END
,j.TERM_DATE AS TERM_DATE
,CASE occ.[EMP_STATUS] WHEN 'FTP' THEN 'FP' WHEN 'PTP' THEN 'PP' WHEN 'AIP' THEN 'AI' WHEN 'AON' THEN 'AO' ELSE occ.[EMP_STATUS] END AS [EMP_STATUS]
,R.RANK_GROUP_DESC
,R.RANK_DESC
,R.RANK_CODE
,e.GENDER
,TB.TIME_OK
FROM
SQLxxxxxxx
--get the current occupancy for the date
INNER JOIN
(
SELECT *
FROM (
SELECT EMPLOYEE_NO,
JOB_NO,
PORTION_START,
OCCUP_COM_REAS,
ADMIN_LOCATION,
PAYPOINT,
OCCUP_POS_TITLE,
PORTION_END,
EMP_STATUS,
ROW_NUMBER() OVER(PARTITION BY EMPLOYEE_NO ORDER BY PORTION_START DESC) as rn
FROM xxxxxxxx) OCC
WHERE occ.rn = 1
) occ on occ.employee_no = e.employee# and occ.rn = 1
--get the current job for the date
INNER JOIN xxxx on e.EMPLOYEE# = j.EMPLOYEE# and j.JOB# = occ.JOB_NO
LEFT JOIN xxx ON J.TERM_REASON=TC.CODE AND TC.KIND='TERM_REASON'
LEFT JOIN xxx ON occ.OCCUP_COM_REAS=TOO.CODE AND TOO.KIND='OCCUP_COM_REAS'
LEFT JOIN xxx.DBO.MASTER_DESC T ON occ.[ADMIN_LOCATION]=T.TEAM_CODE
LEFT JOIN xxx.DBO.MASTER_DESC O ON LEFT([PAYPOINT],1)+CASE J.COMPANY_CODE WHEN '01' THEN '10' WHEN '02' THEN '20' END=O.OFFICE_CODE
LEFT JOIN xxx.DBO.HBM_PERSNL P ON P.EMPLOYEE_CODE = J.PAYROLL#
LEFT JOIN xxx.DBO.TBM_PERSNL TB ON TB.EMPL_UNO = P.EMPL_UNO
LEFT JOIN xxx.DBO.MASTER_DESC R ON TB.RANK_CODE = R.RANK_CODE
LEFT JOIN xxxdbo].[xxx_codes] flex on flex.code = e.aboriginality
--have had to join to HR data as not all occupancy records
--LEFT JOIN xxx.[xxx].[dbo].[EMPLTABLE] emp on emp.emplid = e.employee#
--LEFT JOIN xxxT ON
WHERE 1=1
and e.employee# NOT IN ('022288', '020241')
AND TB.TIME_OK = 'Y'
AND TB.RANK_CODE IN ('1', '2', '3', '4', '5', '6', '8', '9', '10', '11','12', '26', '29', '31', '400', '500', '600', '650', '800', '900' )
AND OCC.PORTION_END >=getdate()
AND OCC.PORTION_START <= ? AND OCC.Portion_End >= ?
So the error is on the bottom line -
Code:
AND OCC.PORTION_START <= ? AND OCC.Portion_End >= ?