12
返回列表 发新帖
楼主: iyyiyy

这个语句错在那里

[复制链接]
论坛徽章:
1
授权会员
日期:2005-10-30 17:05:33
11#
发表于 2004-7-1 16:17 | 只看该作者
insert into InvPosition_luyin(cwhcode,cwhname,cposcode,cposname,ceng,lie,@pp) values(@cwhcode,@cwhname,@cposcode,@cposname,left(@cposcode,2),substring(@cposcode,2,2),+@value)
这个里面@pp处是非法的 此处不能使用变量 有个变通的办法
贴出来你看看
declare @cwhcode varchar(10)
declare @cwhname varchar(20)
declare @cposcode varchar(20)
declare @cposname varchar(30)
declare @value varchar(80)

declare @sql varchar(255)

select @cwhcode='''a101'''
select @cwhname='''a102'''
select @cposcode='''aaa'''
select @cposname='''a104'''
select @value='''a105'''

declare @pp varchar(20)
select @pp ='p3'

select @sql='insert into InvPosition_luyin(cwhcode,cwhname,cposcode,cposname,ceng,lie,'+@pp +') values('+@cwhcode+','+@cwhname+','+@cposcode+','+@cposname+',left('+@cposcode+',2),substring('+@cposcode+',2,2),'+@value+')'

exec(@sql)
我做了些修改 这样就可以解决上面所说的不能使用变量的问题 希望对你有所帮助

使用道具 举报

回复
论坛徽章:
2
2008新春纪念徽章
日期:2008-02-13 12:43:03
12#
发表于 2004-7-2 14:12 | 只看该作者

Re: 多谢斑竹,再求教。

最初由 iyyiyy 发布
[B]我去掉exec确实成功了。再请教一下。
第一:如果不去掉exec有没有成功的可能性,如果有,具体怎么写?
第二:
下面这个语句错在哪里,千万请帮我指正,多谢多谢。
declare @cwhcode varchar(10)
declare @cwhname varchar(20)
declare @cposcode varchar(20)
declare @cposname varchar(30)
declare @value varchar(80)
select @cwhcode='a101'
select @cwhname='a102'
select @cposcode='103'
select @cposname='a104'
select @value='a105'

declare @pp varchar(20)
select @pp ='p3 '
insert into InvPosition_luyin(cwhcode,cwhname,cposcode,cposname,ceng,lie,@pp) values(@cwhcode,@cwhname,@cposcode,@cposname,left(@cposcode,2),substring(@cposcode,2,2),+@value)

执行时,提示:@pp附近有语法错误。
----------------------------天那,错在哪里? [/B]



正好最近为解决固定资产模块的用户需求,写了很多类似的脚本,看看下面的脚本是否可行,也请各位高手指正:

declare @cwhcode varchar(10)
declare @cwhname varchar(20)
declare @cposcode varchar(20)
declare @cposname varchar(30)
declare @value varchar(80)
select @cwhcode='a101'
select @cwhname='a102'
select @cposcode='103'
select @cposname='a104'
select @value='a105'

declare @pp varchar(20)
select @pp ='p3 '


Exec('insert into InvPosition_luyin(cwhcode,cwhname,cposcode,cposname,ceng,lie,'+@pp+') values('+''''+@cwhcode+''''+','+''''+@cwhname+''''+','+''''+@cposcode+''''+','+''''+@cposname+''''+',left('+''''+@cposcode+''''+',2),substring('+''''+@cposcode+''''+',2,2),'+''''+@value+''''+')')
--select 'insert into InvPosition_luyin(cwhcode,cwhname,cposcode,cposname,ceng,lie,'+@pp+') values('+''''+@cwhcode+''''+','+''''+@cwhname+''''+','+''''+@cposcode+''''+','+''''+@cposname+''''+',left('+''''+@cposcode+''''+',2),substring('+''''+@cposcode+''''+',2,2),'+''''+@value+''''+')'


--或者
declare @sql varchar(255)

select @sql='insert into InvPosition_luyin(cwhcode,cwhname,cposcode,cposname,ceng,lie,'+@pp+') values('+''''+@cwhcode+''''+','+''''+@cwhname+''''+','+''''+@cposcode+''''+','+''''+@cposname+''''+',left('+''''+@cposcode+''''+',2),substring('+''''+@cposcode+''''+',2,2),'+''''+@value+''''+')'

exec(@sql)

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表