帮忙看看一条简单sql,先解决先得分!!!

etherealkite 2008-03-31 10:29:09
alter table hello add @a decimal(@length,@dec)
本条语句中hello是一个常量表,@a是一个列名变量,@length是列长度变量,@dec是列小数位数变量
但是提示这条语句有错,请帮忙解决,谢谢,是不是变量周围要打什么引号什么的?
...全文
162 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
-狙击手- 2008-03-31
  • 打赏
  • 举报
回复
晕,晕,
-狙击手- 2008-03-31
  • 打赏
  • 举报
回复
顶龟
dawugui 2008-03-31
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 happyflystone 的回复:]
同意个屁呀

上面那个最后应该是括号,我写错了


SQL codeexec('alter table hello add '+@a +' decimal('+ltrim(@length)+','+ltrim(@dec)+')')



[/Quote]

同意你写错了.
wangxuelid 2008-03-31
  • 打赏
  • 举报
回复
[Quote=引用楼主 etherealkite 的帖子:]
alter table hello add @a decimal(@length,@dec)
本条语句中hello是一个常量表,@a是一个列名变量,@length是列长度变量,@dec是列小数位数变量
但是提示这条语句有错,请帮忙解决,谢谢,是不是变量周围要打什么引号什么的?

[/Quote]


declare @a varchar(20)
declare @length int
declare @dec int
set @a='sss'
set @length=18
set @dec=4

exec('alter table sc add '+@a+' decimal('+ @length +' ,'+ @dec +') ')
wzy_love_sly 2008-03-31
  • 打赏
  • 举报
回复
不连sql好象抱错误
wzy_love_sly 2008-03-31
  • 打赏
  • 举报
回复
create table hello(id int)

declare @sql varchar(100),@a varchar(10),@length int,@dec int
select @a='name',@length=5,@dec=2
set @sql='alter table hello add '+@a+' decimal('+ltrim(@length)+','+ltrim(@dec)+')'
exec( @sql )

select * from hello
-狙击手- 2008-03-31
  • 打赏
  • 举报
回复
同意个屁呀

上面那个最后应该是括号,我写错了

exec('alter table hello add '+@a +' decimal('+ltrim(@length)+','+ltrim(@dec)+')')  


dawugui 2008-03-31
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 happyflystone 的回复:]
SQL codeexec('alter table hello add '+@a +'decimal('+ltrim(@length)+','+ltrim(@dec)+''')
[/Quote]
同意,只能使用动态SQL.
-狙击手- 2008-03-31
  • 打赏
  • 举报
回复
declare @a varchar(10)
declare @length int
declare @dec int
set @a = 'aaa'
set @length = 12
set @dec = 2
exec('alter table hello add '+@a +' decimal('+ltrim(@length)+','+ltrim(@dec)+')')
-狙击手- 2008-03-31
  • 打赏
  • 举报
回复
exec('alter table hello add '+@a +'decimal('+ltrim(@length)+','+ltrim(@dec)+''') 

34,590

社区成员

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

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