笔记30 like语句的sql并接
笔记30 like语句的sql并接
1 --like语句的sql并接 2 declare @CdtSQL varchar(max) 3 SET @CdtSQL = @CdtSQL + 'and CT_OuterCard.VC_OC_Company like ''%' 4 print @CdtSQL -- 因为@CdtSQL没给初始值会是null,所以null + 'and CT_OuterCard.VC_OC_Company like ''%',得到的结果还是null 5 SET @CdtSQL = '' -- 设定初始值为空字符串后,空字符串 + 'and CT_OuterCard.VC_OC_Company like ''%'才会正常显示,所以这次PRINT才会有值 6 SET @CdtSQL = @CdtSQL + 'and CT_OuterCard.VC_OC_Company like ''%' 7 PRINT @CdtSQL 8 9 10 --两种写法的比较 11 declare @CdtSQL varchar(max) 12 SET @CdtSQL = '' 13 set @CdtSQL =@CdtSQL + 'and CT_OuterCard.VC_OC_Company like %' 14 print @CdtSQL 15 SET @CdtSQL = '' 16 SET @CdtSQL = @CdtSQL + 'and CT_OuterCard.VC_OC_Company like ''%' 17 PRINT @CdtSQL