动态sql 问题

xs0573 2012-04-13 04:42:25
最近准备把以前access做的考勤软件,做到sql里面,结果出现了一个存储过程报错

报错提示是:

名称'undate 员工表 set 员工表.bc = 员工调整.sz from 员工表 inner join 员工调整 on 员工表.ny = 员工调整.ny and
员工表.xm = 员工调整.xm where 员工表.ny = 1203 and 员工调整.lm = bc' 不是有效的标示符
...全文
56 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xs0573 2012-04-16
  • 打赏
  • 举报
回复
问题解决了,非常感谢
xs0573 2012-04-13
  • 打赏
  • 举报
回复
好的,等到周一的时候我试试,谢谢
唐诗三百首 2012-04-13
  • 打赏
  • 举报
回复
try this,

ALTER PROCEDURE dbo.月考勤前序
(@ny char(4))
AS
declare @sql varchar(250)
declare @lm varchar(20)

declare c cursor fast_forward for
select lm from 员工调整 where 员工调整.ny = @ny group by lm

open c
fetch next from c into @lm

while @@fetch_status= 0
begin
set @sql = 'update 员工表 set 员工表.' + @lm +' = 员工调整.sz from 员工表 inner join 员工调整 on 员工表.ny =员工调整.ny
and 员工表.xm = 员工调整.xm where 员工表.ny='''+ @ny + ''' and 员工调整.lm='''+convert(varchar(10),@lm)+''' '
exec(@sql)
fetch next from c into @lm
end
close c
deallocate c
唐诗三百首 2012-04-13
  • 打赏
  • 举报
回复
try this,

ALTER PROCEDURE dbo.月考勤前序
(@ny char(4))
AS
declare @sql varchar(250)
declare @lm varchar(20)

declare c cursor fast_forward for
select lm from 员工调整 where 员工调整.ny = @ny group by lm

open c
fetch next from c into @lm

while @@fetch_status= 0
begin
set @sql = 'update 员工表 set 员工表.' + @lm +' = 员工调整.sz from 员工表 inner join 员工调整 on 员工表.ny =员工调整.ny
and 员工表.xm = 员工调整.xm where 员工表.ny = '+ @ny + ' and 员工调整.lm ='+convert(varchar(10),@lm)
exec(@sql)
fetch next from c into @lm
end
close c
deallocate c
xs0573 2012-04-13
  • 打赏
  • 举报
回复
员工调整 列表类型
ny char(4)
xm varchar(20)
lm nvarchar(20)
sz varchar(50)
员工表 列表类型
ny char(4)
xm varchar(20)
bc int(4)
请帮我看看具体是哪里出问题了
要是能帮我看下如何在优化下,就太感谢了~~=。=
xs0573 2012-04-13
  • 打赏
  • 举报
回复
具体程序是

ALTER PROCEDURE dbo.月考勤前序
(@ny char(4))
AS
declare @sql varchar(250)
declare @lm varchar(20)

declare c cursor fast_forward for
select lm from 员工调整 where 员工调整.ny = @ny group by lm

open c
fetch next from c into @lm

while @@fetch_status= 0
begin
set @sql = 'update 员工表 set 员工表.' + @lm +' = 员工调整.sz from 员工表 inner join 员工调整 on 员工表.ny =员工调整.ny
and 员工表.xm = 员工调整.xm where 员工表.ny = '+ @ny + ' and 员工调整.lm ='+convert(varchar(10),@lm)
exec @sql
fetch next from c into @lm
end
close c
deallocate c

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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