日期:2014-05-18  浏览次数:20403 次

奇怪疑问 !行集合不能作为标签
[code=SQL][/code]代码如下:
VB code

Private Sub Command1_Click()
Set db = New ADODB.Connection
Set rs = New ADODB.Recordset
db.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=lzjc;Data Source=."
db.Open
If Option1.Value = True Then
rs.Open "declare @a varchar(20) set @a=(select DateName(year,GetDate())) select sum(收入) as 第一月销售总金额  from ri where 日期 between  LTRIM(@a)+'-9-1' and LTRIM(@a)+'-9-30'", db, adOpenStatic, adLockReadOnly
Set DataGrid1.DataSource = rs
End If
End Sub

运行提示 行集合不能作为标签
改了
SQL code
declare @a varchar(20) set @a=(select DateName(year,GetDate())) select sum(收入) as 第一月销售总金额  from ri where 日期 between  LTRIM(@a)+'-9-1' and LTRIM(@a)+'-9-30'
SQL code
select sum(收入) as 第一月销售总金额  from ri where 日期 between '2009-9-1' and '2009-9-30'
就能成功

------解决方案--------------------
select sum(收入) as 第一月销售总金额
from ri 
where 日期 between LTRIM(@a)+'-09-01' and LTRIM(@a)+'-09-30'