如何在这个sql Query中传递一个参数

时间:2013-10-09 06:51:33

标签: sql sql-server

Select  
    CAST(
        CAST(N'' AS XML).value(
            'xs:base64Binary("MA==")'
          , 'VARBINARY(MAX)'
        ) 
        AS VARCHAR(MAX)
    )   ASCIIEncoding
;

Declare @Value nvarchar(10)
set @Value ='MA=='
Select  
    CAST(
        CAST(N'' AS XML).value(
            'xs:base64Binary("@Value")'
          , 'VARBINARY(MAX)'
        ) 
        AS VARCHAR(MAX)
    )   ASCIIEncoding
;

收到错误

1 个答案:

答案 0 :(得分:0)

这有效:

Declare @Value nvarchar(10)
set @Value ='MA=='
Select  
    CAST(
        CAST(N'' AS XML).value(
            'xs:base64Binary(sql:variable("@Value"))'
          , 'VARBINARY(MAX)'
        ) 
        AS VARCHAR(MAX)
    )   ASCIIEncoding
;