私は現在、次のSQLクエリを実行して立ち往生しています:SQL Server 2008の結果の文字列置換 - マルチ識別子
SELECT
c.[DeviceName],
STUFF((SELECT ' + ' + sw.[SuiteName] FROM [dbo].[AppSoftwareSuites] as sw where sw.[Computer_Idn] = c.[Computer_Idn] AND sw.[SuiteName] like 'CFRM-Server%' FOR XML PATH('')),1,3,'') AS 'CFRM',
STUFF((SELECT ' + ' + sw.[SuiteName] FROM [dbo].[AppSoftwareSuites] as sw where sw.[Computer_Idn] = c.[Computer_Idn] AND sw.[SuiteName] like 'Communication Module%' FOR XML PATH('')),1,3,'') AS 'Communication Module',
STUFF((SELECT ' + ' + sw.[SuiteName] FROM [dbo].[AppSoftwareSuites] as sw where sw.[Computer_Idn] = c.[Computer_Idn] AND sw.[SuiteName] like 'GEBIT-Commons-Java%' FOR XML PATH('')),1,3,'') AS 'Gebit Commons Java',
STUFF((SELECT ' + ' + sw.[SuiteName] FROM [dbo].[AppSoftwareSuites] as sw where sw.[Computer_Idn] = c.[Computer_Idn] AND sw.[SuiteName] like 'GEBIT-Commons_JBOSS%' FOR XML PATH('')),1,3,'') AS 'Gebit Commons JBOSS',
STUFF((SELECT ' + ' + sw.[SuiteName] FROM [dbo].[AppSoftwareSuites] as sw where sw.[Computer_Idn] = c.[Computer_Idn] AND sw.[SuiteName] like 'Mobile Store%' FOR XML PATH('')),1,3,'') AS 'Mobile Store',
STUFF((SELECT ' + ' + sw.[SuiteName] FROM [dbo].[AppSoftwareSuites] as sw where sw.[Computer_Idn] = c.[Computer_Idn] AND sw.[SuiteName] like 'NEWPOSS-Store-Server%' FOR XML PATH('')),1,3,'') AS 'NEWPOSS',
STUFF((SELECT ' + ' + sw.[SuiteName] FROM [dbo].[AppSoftwareSuites] as sw where sw.[Computer_Idn] = c.[Computer_Idn] AND sw.[SuiteName] like 'Store Portal - Complete%' FOR XML PATH('')),1,3,'') AS 'Store Portal',
STUFF((SELECT ' + ' + sw.[SuiteName] FROM [dbo].[AppSoftwareSuites] as sw where sw.[Computer_Idn] = c.[Computer_Idn] AND sw.[SuiteName] like 'Store S&R Services%' FOR XML PATH('')),1,3,'') AS 'SSR'
FROM
[dbo].[Computer] as c WITH (NOLOCK)
WHERE
c.[DeviceName] LIKE '%STL01'
ORDER BY
c.[DeviceName] ASC;
出力は結構ですが、それはデータベースに(「SSR」の)1つの製品と思われます壊れた出力( '& R Services xx.xx.xx'の代わりに 'Store S & R Services')につながる「&」文字があります。
出力で文字列置換を実行する可能性はありますか?
「For XML」の理由は、データベース内のDeviceNameごとに2つのエントリが存在するために空の結果になるためです。
すべてのヘルプは高く評価され:)