我觉得好象没有必要用过程,用select 语句不就解决问题了么??!

解决方案 »

  1.   

    是在写一个触发器,我要动态访问inserted某写列的值
      

  2.   

    例如:
    我现在获取某列的值使用
    select @ColValue = 列名 from inserted
    现在我想把列名作为动态的
    select @ColValue = @ColName from inserted
    但是行不通?怎么办?
      

  3.   

    只能使用exec 来获得  不能直接在语句里加入变量当成字符的
      

  4.   

    create table aii (id int ,ii int)
    insert into aii select 1,2
    go
    create proc proc_aiii
    @na nvarchar(100),@n int output
    as
    declare @sql nvarchar(100)
    select @sql='select @out='+@na+' from aii'
    execute sp_executesql @sql,N'@out int output',@n output
    --run
    declare @out int
    execute proc_aiii 'id',@out output
    print convert(varchar(100),@out)不太明白你的意思,你是不是需要根据列命来查询相应的值
    给你一个例题参考
      

  5.   

    我写的触发器为什么不对?CREATE TRIGGER [Create_CFDB] ON dbo.测风塔 
    FOR INSERT
    ASdeclare @colName nvarchar(20)
    declare @value float
    declare @strSql nvarchar(300)set @colName = N'类型为float的列名'
    set @strSql = N'select @outFloat = [' + @colName + N'] from inserted'
    execute sp_executesql @strSql, N'@outFloat float output', @value output我的目的是将名为@colName的列的值赋给@value运行时出现错误“对象名inseted无效”
      

  6.   

    CREATE TRIGGER [Create_CFDB] ON dbo.测风塔 
    FOR INSERT
    ASdeclare @colName nvarchar(20)
    declare @value float
    declare @strSql nvarchar(300)select * into #xx from insertedset @colName = N'类型为float的列名'
    set @strSql = N'select @outFloat = [' + @colName + N'] from #xx'
    execute sp_executesql @strSql, N'@outFloat float output', @value output