【发布时间】:2015-01-13 00:57:38
【问题描述】:
我写了我的第一个 sql Server 返回表 UDF,因为我认为比使用 SP 更好 但是,虽然可以很容易地从 sql server 检索结果.. 我无法从经典的 ASP ADO 调用它得到结果
UDF如下:
CREATE FUNCTION dbo.udf_Alert
(
@I nvarchar (30),
@L nvarchar (10)
)
RETURNS TABLE AS RETURN
(
SELECT a.Message, a.Height, a.backgroundColor, a.isFree
from Advice a
join ActiveMessages b on b.MessageID=a.MessageID
join Items i on b.ItemID=i.ItemID
join Sellers s on i.UserID=s.UserID
join Users u on u.UID=s.UID
WHERE
(i.ItemID=@I and a.Active='1' and b.Active='1' and i.active='1' and i.Show='1' and CHARINDEX('ALERT',u.Modules)>0
and a.ValidFrom<GETDATE() and a.ValidTo>GETDATE() and u.PaidUntil>GETDATE() and charindex(@L,a.Languages)>-1 or charindex('all',a.Languages)>-1 )
UNION ALL
SELECT a.Message, a.Height, a.backgroundColor, a.isFree
FROM Advice a, Users u
WHERE u.isFree='1' and a.isFree='1' and (CHARINDEX(@L,a.Languages)>-1 or Charindex('all',a.Languages)>-1)
)
我可以轻松地从 SSMS 调用中执行
Select * from dbo.udf_Alert('281F50246','fr')
但我必须嵌入一个经典的 ASP 例程,但我还没有找到方法..
尝试了SP方法..但尝试设置参数时出现错误: 这是我尝试过的:
sql="Select dbo.udf_Alert('xx','yy')"
dim cmdA
set cmdA = Server.CreateObject("ADODB.Command")
cmdA.ActiveConnection= cn
cmdA.CommandType=4
cmdA.CommandText=sql
cmda.Parameters.Append cmdA.CreateParameter("fd", nvarchar, adParamInput,30, itemID)
cmda.Parameters.Append cmdA.CreateParameter("fde", nvarchar, adParamInput,10, LanguageID)
' cmdA.Parameters("@I")=ItemID '<-----ERRROR HERE
' cmdA.Parameters("@L")=LanguageID
set rs=cmdA.Execute()
所以我尝试以其他方式设置参数.. 但得到了相同的结果:
ADODB.Command error '800a0bb9'
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
可以提出一些建议吗?
谢谢 塞尔吉奥
【问题讨论】:
标签: sql-server asp-classic ado user-defined-functions