1

我没有在选择语句参数中获得变量 rsp2 的值。

 DECLARE @RSP  varchar(50)
  DECLARE @RSP2 varchar(50)
 SET @RSP =  '(<DL>,<DM>)'
SELECT @RSP  
 SET @RSP2 = REPLACE(REPLACE(REPLACE(REPLACE(@RSP,'(',''),')',''),'<',''''),'>','''')
SELECT @RSP2 
    SELECT [F_YEAR] FROM tbl1 WHERE 
                 RSP  IN (@RSP2)
4

3 回答 3

1

假设您希望将 的值f_year分配给@rsp变量。

DECLARE @RSP  varchar(50)
      , @RSP2 varchar(50);

 SET @RSP = '(<DL>,<DM>)';
 SET @RSP2 = REPLACE(REPLACE(REPLACE(REPLACE(@RSP,'(',''),')',''),'<',''''),'>','''');

SET @RSP = (
  SELECT Max(f_year)
  FROM   tbl1
  WHERE  RSP  = @RSP2;
);

SELECT @RSP  As rsp
     , @RSP2 As rsp2;
于 2013-09-09T11:42:55.133 回答
0

尝试这个。

DECLARE @RSP  varchar(50)
DECLARE @RSP2 varchar(50)
SET @RSP =  '(<DL>,<DM>)'
SELECT @RSP  
SET @RSP2 = REPLACE(REPLACE(REPLACE(REPLACE(@RSP,'(',''),')',''),'<',''''),'>','''')
SELECT @RSP2 
EXEC('SELECT [F_YEAR] FROM tbl1 WHERE 
             RSP  IN ('+@RSP2+')')

希望对你有帮助

谢谢

于 2013-09-09T12:02:15.530 回答
0
DECLARE @RSP  varchar(50) = '(<DL>,<DM>)'
DECLARE @RSP2 varchar(50)
-- next line has been changed as well
SET @RSP2 = REPLACE(REPLACE(REPLACE(REPLACE(@RSP,'(',''),')',''),'<',''),'>','')
SELECT @RSP RSP, @RSP2 RSP2 

SELECT [F_YEAR] FROM tbl1 
WHERE RSP in (
SELECT t.c.value('.', 'VARCHAR(20)')
FROM (
SELECT x = CAST('<t>' + 
    REPLACE(@RSP2, ',', '</t><t>') + '</t>' AS XML)
) a
CROSS APPLY x.nodes('/t') t(c))
于 2013-09-09T12:05:12.983 回答