我有一个存储过程可以执行我期望它在SQL中返回我输入的任何年份的数据,但是我很难将存储过程绑定到Excel电子表格,这将不允许我这样做由于在尝试将varchar转换为int时返回的错误。这是一个相对较小的SQL,但实际上我想将@Year
参数绑定到最终用户的Excel单元格。
它声明在Excel中将数据类型varchar转换为tinyint“
我在Excel中的定义字符串:
执行dbo.StoredProcedure'年'
存储过程:
@Year Tinyint
AS
SELECT DBO.users.loginname,
Cast(Datename(M, DBO.contractdate.contractdate) AS VARCHAR) AS DatePeriod,
Sum(CASE
WHEN DBO.contract.contract = 1 THEN 1
ELSE 0
END) AS Contract,
Sum(CASE
WHEN DBO.contract.contract = 0 THEN 1
ELSE 0
END) AS Permanant
FROM DBO.contractskill
INNER JOIN DBO.users
INNER JOIN DBO.contract
ON DBO.users.userid = DBO.contract.userid
INNER JOIN DBO.contractdate
ON DBO.contract.contractid = DBO.contractdate.contractid
ON DBO.contractskill.contractid = DBO.contract.contractid
WHERE ( DBO.contractdate.dns = 0 )
AND ( DBO.contractskill.skillid = 30960 )
AND Year(DBO.contractdate.contractdate) = @Year
GROUP BY Cast(Datename(M, DBO.contractdate.contractdate) AS VARCHAR),
Month(DBO.contractdate.contractdate),
DBO.users.loginname
ORDER BY Month(DBO.contractdate.contractdate)