请教一个SQL 的问题。在以下语句中 在where 的后面我需要加个条件,但是加了总提示错误。
ALTERprocufdata(@chrWherevarchar(1000))asDECLARE@textvarchar(10)DECLARE@chrsqlvarchar...
ALTER proc ufdata(@chrWhere varchar(1000))
as
DECLARE @text varchar(10)
DECLARE @chrsql varchar(1000)
select @text=SUBSTRING(@chrWhere,5,10)
if ltrim(rtrim(@chrWhere)) <> ''
BEGIN
set @chrsql='select cwhcode,sum( isnull(iainprice,0))-sum(isnull(iaoutprice,0)) 金额
into table_01_01
from IA_Subsidiary
where dkeepdate<='''+@text+'''
group by cwhcode'
If exists(select name from sysobjects where name ='table_01_01')
Drop table table_01_01
end
else
begin
set @chrsql='select cwhcode,sum( isnull(iainprice,0))-sum(isnull(iaoutprice,0)) 金额
into table_01_01
from IA_Subsidiary
group by cwhcode'
If exists(select name from sysobjects where name ='table_01_01')
Drop table table_01_01
end
print @chrsql
exec(@chrsql)
---------------------------------------
在以上语句中 在where 的后面我需要加个条件,但是加了总提示错误。例如
where dkeepdate<='''+@text+''' and ddate>='2011-12-31'
请问我该如何加?ddate字段为日期型的。 展开
as
DECLARE @text varchar(10)
DECLARE @chrsql varchar(1000)
select @text=SUBSTRING(@chrWhere,5,10)
if ltrim(rtrim(@chrWhere)) <> ''
BEGIN
set @chrsql='select cwhcode,sum( isnull(iainprice,0))-sum(isnull(iaoutprice,0)) 金额
into table_01_01
from IA_Subsidiary
where dkeepdate<='''+@text+'''
group by cwhcode'
If exists(select name from sysobjects where name ='table_01_01')
Drop table table_01_01
end
else
begin
set @chrsql='select cwhcode,sum( isnull(iainprice,0))-sum(isnull(iaoutprice,0)) 金额
into table_01_01
from IA_Subsidiary
group by cwhcode'
If exists(select name from sysobjects where name ='table_01_01')
Drop table table_01_01
end
print @chrsql
exec(@chrsql)
---------------------------------------
在以上语句中 在where 的后面我需要加个条件,但是加了总提示错误。例如
where dkeepdate<='''+@text+''' and ddate>='2011-12-31'
请问我该如何加?ddate字段为日期型的。 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询