日期:2014-05-16 浏览次数:20647 次
declare @StrSql varchar(2000)
declare @ContractIds varchar(2000)
set @ContractIds='123,3,66|444,33,666'
SELECT @StrSql = ';WITH [temp_tab] AS (SELECT '
+ Replace( Replace(@ContractIds, ',', ' AS ContractId,'), '|', ' AS ClassScheduleId union all SELECT ' )
+ ' AS ClassScheduleId) '
print @StrSql
--实际输出 ;WITH [temp_tab] AS (SELECT 123 AS ContractId,3 AS ContractId,66 AS ClassScheduleId union all SELECT 444 AS ContractId,33 AS ContractId,666 AS ClassScheduleId)
--按照自己的理解,应该是下面这样的呀!
Replace( Replace(@ContractIds, ',', ' AS ContractId,'), '|', ' AS ClassScheduleId union all SELECT ' ) + ' AS ClassScheduleId
'123 AS ContractId,3,66 AS ClassScheduleId union all SELECT 444,33,666 AS ClassScheduleId'