导航
  • 主页
  • 基础类
  • 应用实例
  • 新技术前沿

出错

My_first 2003-01-13 10:35:30
set @sql = 'declare cur_id cursor for select max('+'dh'+') from mxsb where convert(char(10),mdate,120)='''+@Mydate+''''
exec(@sql)
Open cur_id
fetch next from cur_id into @Maxid


改为下面的就出错
set @sql = 'declare cur_id cursor for select max('+'dh'+') from mxsb where substring(dh,12,4) as char)='+@userbh+'convert(char(10),mdate,120)='''+@Mydate+''''
exec(@sql)
Open cur_id

我加了一句substring(dh,12,4) as char)='+@userbh+'
...全文
5 点赞 收藏 7
写回复
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
语法不对,应为:
set @sql = 'declare cur_id cursor for select max('+'dh'+') from mxsb where substring(dh,12,4) as char)='+@userbh+'convert(char(10),mdate,120)='''+@Mydate+''''
回复
KnowLittle 2003-01-13
是"找感觉"这个意思吗?不会巴,这么简单,楼主会不知道吗?
回复
zqllyh 2003-01-13


exec('declare cur_id cursor for select max( dh) from mx
sb
where substring(dh,12,4) ='+ @userbh + ' and convert(char(10),mdate,120)= ' + @Mydate )
回复
nielisheng 2003-01-13
substring(dh,12,4) as char

or substring(dh,12,4) = '+@userbh+'
回复
KnowLittle 2003-01-13
你加的这个什么意思?
回复
zqllyh 2003-01-13


declare @mydate char(10),@sql varchar(3000),@userbh char(10)
set @sql = 'declare cur_id cursor for select max('+'dh'+') from mxsb
where substring(dh,12,4) ='+@userbh+ ' and convert(char(10),mdate,120)='''+@Mydate+''''
exec(@sql)
回复
CABO 2003-01-13
max('+'dh'+')

是什么写法?好像还没见过

可以加一个GROUP BY,或者用子查询
回复
发动态
发帖子
MS-SQL Server
创建于2007-09-28

3.2w+

社区成员

MS-SQL Server相关内容讨论专区
申请成为版主
社区公告
暂无公告