John Doe
3/31/2007 4:15:00 PM
[ Ronald S. Cook ] wrote the following message on [ 3/31/2007 7:49 AM PST ]:
> DECLARE @MyString varchar(50)
> SET @MyString = 'X, Y, Z'
>
> SELECT *
> FROM MyTable
> WHERE Code IN (@MyString)
>
> Any way I can do what I'm trying to do?
-- This'll work without getting into dynamic sql...
DECLARE @argXML VARCHAR(100)
SET @argXML =
'<args><code>X</code><code>Y</code><code>Z</code></args>'
DECLARE @temptable TABLE (code CHAR(1), data VARCHAR(20))
INSERT INTO @temptable VALUES ('X', 'Test X 1');
INSERT INTO @temptable VALUES ('Y', 'Test Y 1');
INSERT INTO @temptable VALUES ('Z', 'Test Z 1');
INSERT INTO @temptable VALUES ('A', 'Test A 1');
INSERT INTO @temptable VALUES ('B', 'Test B 1');
INSERT INTO @temptable VALUES ('C', 'Test C 1');
INSERT INTO @temptable VALUES ('X', 'Test X 2');
INSERT INTO @temptable VALUES ('Y', 'Test Y 2');
INSERT INTO @temptable VALUES ('Z', 'Test Z 2');
INSERT INTO @temptable VALUES ('X', 'Test X 3');
INSERT INTO @temptable VALUES ('Y', 'Test Y 3');
INSERT INTO @temptable VALUES ('Z', 'Test Z 3');
DECLARE @error INT
,@idoc INT
EXEC sp_xml_preparedocument @idoc OUTPUT, @argXML
SELECT x.code, t.data
FROM @temptable t
JOIN OPENXML (@idoc, '//args/code',1)
WITH (code CHAR( 1) '.')
x ON t.code = x.code
EXEC sp_xml_removedocument @idoc