Tuesday, 18 September 2018

Sql, read tables thos id in anther table in a One column

questionIds
1,6,7,2,3,4,5,8,13,14




DECLARE @xml AS XML,
@str AS VARCHAR(100),
@delimiter AS VARCHAR(10);
select @str=QuestionIds from dbo.ExamQuestions
SET @delimiter = ',';
SET @xml = CAST('<X>' + REPLACE(@str, @delimiter, '</X><X>') + '</X>' AS XML);

--select @xml
select * from dbo.question where questionId in(
SELECT [N].value( '.', 'varchar(50)' ) AS value FROM @xml.nodes( 'X' ) AS [T]( [N] )
)

No comments:

Post a Comment

IIS deployment support details

  Node JS - IIS deployment support details node: http://go.microsoft.com/?linkid=9784334 IISNode: https://github.com/azure/iisnode/releases/...