str = "update photos set zid="&ZID&" where  pid in (select top 10 pid from photos where userid='"&user&"' and aid='"&aid&"' order by pid  ) "response.write "*****" & str & "****"try to run the statement between "***" in the query analyzer to make sure it works as is

解决方案 »

  1.   

    --这句话在sqlserver的查询分析器更新的十条数据??
    应该是更新符合userid和aid条件记录的前10条的所有数据。
      

  2.   

    不好意思,我描述的不太清楚,我的意思是说在asp页面中,top 后面的数字失效  我试着写了一下存储过程又发现一个问题过程是这样CREATE proc Insert_MainAlbum
    @quantity int
    asupdate photos set zid=100016 where  pid in (select top @quantity pid from photos where userid='xielk' and aid='78' order by pid )
    GO
    语法检查通不过,它告诉我在top 后面的@quantity后面有语法错误,换数字就可以为什么不能这样写?
      

  3.   

    存储过程中应该这样写:CREATE proc Insert_MainAlbum
    @quantity int
    as
    declare @sql nvarchar(4000)
    set @sql='update photos set zid=100016 where  pid in (select top '+cast(@quantity as varchar)+' pid from photos where userid=''xielk'' and aid=''78'' order by pid '
    exec(@sql)
    GO
      

  4.   

    或:CREATE proc Insert_MainAlbum
    @quantity int
    as
    exec('update photos set zid=100016 where  pid in (select top '+@quantity+' pid from photos where userid=''xielk'' and aid=''78'' order by pid ')
    GO
      

  5.   

    基本上可以了,不过我的userid,aid是字符类型
    如果这样写,查询分析器会在@userid这里报错,我不知道这种写法怎么来区别数值和字符,再帮看看
    exec('update photos set zid='+@Zid+' where  pid in (select top '+@quantity+' pid from photos  where userid='+@userid+' and aid='+@aid+' order by pid )')
      

  6.   

    在字符串中, ''表示'exec('update photos set zid='''+@Zid+''' where  pid in (select top '+@quantity+' pid from photos  where userid='''+@userid+''' and aid='''+@aid+''' order by pid )')
      

  7.   

    exec('update photos set zid='+@Zid+' where  pid in (select top '+@quantity+' pid from photos  where userid='+@userid+' and aid='+@aid+' order by pid )')这句没有错啦,你在定义时要把@userid和@aid+定义为字符型的
    在ASP语句里面先把数据转为字符型再传过来
      

  8.   

    use pubs
    go
    declare @str varchar(100)
    declare @sql nvarchar(4000)
    select @str='1'
    select @sql='update jobs set job_desc='+@str
    exec (@sql)select * from jobs
      

  9.   

    改进一下declare @sql nvarchar(4000)
    select @sql='update photos set zid='+''''+@Zid+''''+' where  pid in (select top '+@quantity+' pid from photos  where userid='+''''+@userid+''''+' and aid='+''''+@aid+''''+' order by pid )'
    2个‘’等于一个‘