set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
gocreate PROCEDURE [dbo].[UpdateList]
@ipUserID int,
@ipFUserID int,
@ipType int
AS
SET NOCOUNT ON
BEGIN
declare @sql1 nvarchar(1000);
select  @sql1 = 'update UserInfo set FriendList.modify(' +'''insert <Friend name      ='+ '"@ipFUserID"'
+' /> as last into (/FriendList)[1]'+''') where FUserID = @ipUserID ;'
execute (@sql1) 

END请问我如何才能将两个变量的值传进该sql语句里,请高手帮忙指点,谢谢!

解决方案 »

  1.   

    @ipFUserID
    @ipUserID 
    變量放引號外面~~
      

  2.   

    FUserID = '+@ipUserID +';'在SQL中是这样,
    字符用
    '''+变量+'''
    整形用上面的
      

  3.   

    Conversion failed when converting the varchar value 'update UserFriendInfo set FriendList.modify('insert <Friend name ="@ipFUserID" /> as last into (/FriendList)[1]') where FUserID = ' to data type int.
      

  4.   

    我改成这样了
    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    gocreate PROCEDURE [dbo].[YX_QP_UpdateFriendList]
    @ipUserID int,
    @ipFUserID int,
    @ipType int
    AS
    SET NOCOUNT ON
    BEGIN
    declare @sql1 nvarchar(1000);
    declare @sql2 nvarchar(1000);
    select  @sql1 = 'update UserFriendInfo set FriendList.modify(' +'''insert <Friend name ='+ '"@ipFUserID"'
    +' /> as last into (/FriendList)[1]'+''') where FUserID = '+@ipUserID+';' 
    execute (@sql1)

    END
    但是还是出错误
    Conversion failed when converting the varchar value 'update UserFriendInfo set FriendList.modify('insert <Friend name ="@ipFUserID" /> as last into (/FriendList)[1]') where FUserID = ' to data type int.
      

  5.   

    拼接字符串的时候int型要显式转成字符型