存储过程这样写有问题吗?

hedy_lu 2011-06-07 08:53:46
@FactoryName varchar(50)
AS
create table table1 (FactoryId int null,totalmonth1 money null)
insert into table1 (FactoryId,totalmonth1)
select tb_User.FactoryId as FactoryId,('$'+ convert( varchar(50),sum(tb_MPCost.MPCost)))as totalmonth1
from tb_MPCost,tb_User,tb_Factory ,tb_CostCenter where
tb_MPCost.PCNumber=tb_User.PCNumber and
tb_CostCenter.CostCenterId=tb_User.CostCenterId
and tb_Factory.FactoryId =tb_User.FactoryId
and tb_Factory.FactoryName= @FactoryName
and tb_MPCost.MPCostTime between convert(varchar(10),DATEADD(day,-DATEPART(DAY,GETDATE())+1,dateadd(month,-1,GETDATE())),23) +' 00:00:00'
and convert(varchar(10),DATEADD(day,-1,DATEADD(month,0,GETDATE()-day(GETDATE())+1)),23)+' 23:59:59'
group by tb_User.FactoryId

drop table table1


为什么老是报这样的错误,请高手帮忙看一下

Msg 260, Level 16, State 1, Procedure FactoryCostTotal, Line 6
Disallowed implicit conversion from data type varchar to data type money, table 'SLFMMS.dbo.table1', column 'totalmonth1'. Use the CONVERT function to run this query.
...全文
117 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
copico 2011-06-07
  • 打赏
  • 举报
回复
create table #table1

不要用 实体表名
唵嘛呢叭咪吽 2011-06-07
  • 打赏
  • 举报
回复
改字段类型
快溜 2011-06-07
  • 打赏
  • 举报
回复
money 类型怎么存字符?我想知道
hedy_lu 2011-06-07
  • 打赏
  • 举报
回复
那怎么修改?



[Quote=引用 3 楼 gefangliang 的回复:]

Disallowed implicit conversion from data type varchar to data type money这句不允许将varchar转换为money类型。
[/Quote]
心灵彩虹 2011-06-07
  • 打赏
  • 举报
回复
Disallowed implicit conversion from data type varchar to data type money这句不允许将varchar转换为money类型。
心灵彩虹 2011-06-07
  • 打赏
  • 举报
回复
中间有go吗?
hedy_lu 2011-06-07
  • 打赏
  • 举报
回复
请教高手
qingcongcuizu 2011-06-07
  • 打赏
  • 举报
回复
改成这样吧:
create table #table1 (FactoryId int null,totalmonth1 varchar(50) null)

62,052

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧