很简单,很烦的问题。求助谢谢

abue 2003-06-14 04:21:42
我有存储过程
create proc hello
@contents varchar(200)
as
select @contents='hi'//这一条语句能执行.
//exec('select '+@contents+'=''hi''')就执行不成功
return
go
///////
执行
declare @hello varchar(200)
exec hello @hello output
select @hello
提示
为什么呀,我很急的。




...全文
41 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjcxc 2003-06-14
  • 打赏
  • 举报
回复
因为我写的处理过程中字段用[]括起来的
所以如果你有多个字段相加的话,就要写成:
declare @value varchar(1000)
exec fgetmergefield '表名','字段名1]+[字段名2]+[字段名3', @value output
print @value
zjcxc 2003-06-14
  • 打赏
  • 举报
回复
这个好办,我查了一下书,这样处理就行了

create procedure fgetmergefield
@tbname varchar(20),@fdname varchar(50),@value varchar(1000) output
as
declare @sql nvarchar(1000),@aa nvarchar(100)
select @sql='select @nn=@nn+['+@fdname+'] from ['+@tbname+']'
select @aa='@nn varchar(1000) output'
select @value=''
exec sp_executesql @sql,@aa, @value output
go

declare @value varchar(1000)
exec fgetmergefield '表名','字段名', @value output
print @value
hjb111 2003-06-14
  • 打赏
  • 举报
回复

try:

create proc hello @tablename varchar(10),@contents varchar(200) output
as
exec('select '+@contents+'='+@contents+'+name from '+@tablename+'')
return
go
hjb111 2003-06-14
  • 打赏
  • 举报
回复
写错了!


create proc hello1 @contents varchar(200)
as
select @contents='hi'
exec('select '+@contents+'=''hi''')
return
go

declare @hello varchar(200)
set @hello='123'
exec hello @hello -- output
select @hello
hjb111 2003-06-14
  • 打赏
  • 举报
回复
create proc hello1 @contents output
as
select @contents='hi'
exec('select '+@contents+'=''hi''') --这个能执行,在我机子上
return
go

declare @hello varchar(200)
set @hello='123'
exec hello @hello -- output
select @hello
abue 2003-06-14
  • 打赏
  • 举报
回复
蚂蚁大哥!
return 只能返回字符串呀
abue 2003-06-14
  • 打赏
  • 举报
回复
是这样的。
以前我有一个问题是想把一行的所有字段加在一起。形成一个字符串。返回去。这个问题已经解决了但是数据的来源是不同的表,表名我可以自由定义。可是一考虑到这个表名。
我就不知所措了。
create proc hello
@tablename varchar(6)
@contents varchar(200) output
as
select @contents=''
select @contents=@contents+filed1+filed2 from @tablename
这么写最后一句总是有错。
CrazyFor 2003-06-14
  • 打赏
  • 举报
回复
create proc hello
@contents varchar(200),
@RV varchar(2000) output
as
select @contents='hi'//这一条语句能执行.
....
return @RV
go
zjcxc 2003-06-14
  • 打赏
  • 举报
回复
drop proc hello
go
create proc hello
@contents varchar(200)
as
declare @sql varchar(300)
select @sql='select '+@contents+'=''hi'''
exec(@sql)
return
go

declare @hello varchar(200)
select @hello='abc'
exec hello @hello-- output
select @hello
zjcxc 2003-06-14
  • 打赏
  • 举报
回复
你的意图想做什么?
abue 2003-06-14
  • 打赏
  • 举报
回复
阿波,
你的那句就是我执行不了的那句
//exec('select '+@contents+'=''hi''')就执行不成功
zjcxc(邹建) 的执行完后是Null

hjb111 2003-06-14
  • 打赏
  • 举报
回复
exec('select '+@contents+'=''hi''')
zjcxc 2003-06-14
  • 打赏
  • 举报
回复
drop proc hello
go
create proc hello
@contents varchar(200)
as
declare @sql varchar(300)
select @sql='select '+@contents+'=''hi'''
exec(@sql)
return
go

declare @hello varchar(200)
exec hello @hello-- output
select @hello
abue 2003-06-14
  • 打赏
  • 举报
回复
提示错误为什么呀。
急呀。
急。

22,207

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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