SQL Server 存储过程之like赋值

------------恢复内容开始------------

1、like后接的是固定的字符串,赋值方式;

   SELECT * FROM Table_1 where loc_type ='STL' and loc_id like 'SL5%'

2、like后接的是可变字符串,赋值方式;

   DECLARE @PCBALabel NVARCHAR(100)

   SELECT * from Table_1 WHERE  WID like @PCBALabel+'%'

      SELECT PCSMODE FROM Table_1 WHERE submodel like '%'+@Model+'%'

3、使用set @sql 查询语句时,like后接固定字符串,赋值方式;

   set @sql = N'SELECT top 1 V.[Value] FROM Table_1 m

   WHERE  m.ITEM LIKE ''%PCB料号%'' ORDER BY f.DocumentVersion DESC, f.lmdate DESC, f.LmTime DESC'

      

4、使用set @sql 查询语句时,like后接可变字符串,赋值方式;

   set @sql = N'SELECT top 1 V.[Value] FROM  Table_1 m
   WHERE  m.ITEM LIKE ''' + @panel + '面-炉温板ID%''  ORDER BY f.DocumentVersion DESC, f.lmdate DESC, f.LmTime DESC'

5、使用set @strsql查询语句且有openquery时,like后接固定字符串,赋值方式;

   set @strsql ='DECLARE cur_pcbapn3h CURSOR FOR'+CHAR(13) + CHAR(10)
   set @strsql =@strsql+'select m.* from ('
   set @strsql =@strsql+'select a.* from '
   set @strsql=@strsql+'(select distinct BCHLD ,BPROD from openquery(bachs,'+''''+'select * from (
   SELECT BMWHS,
           SUBSTR (SYS_CONNECT_BY_PATH (bprod, ''''/''''), 2, 12) rootprod,
           level,
           bprod,
           BCHLD,
           BDEFF,
           BDDIS
         FROM Table_1
   START WITH (sysdate_  between BDEFF and BDDIS)  
   AND bprod =''''' + @pcbapnN + '''''
   CONNECT BY PRIOR BCHLD = BPROD 
   and  (sysdate_  between BDEFF and BDDIS)  ) 
   where bprod like ''''5E._____.M%''''
   and bchld like ''''3H%''''
       order by  rootprod,level,BPROD'')'

6、未完待续……

------------恢复内容结束------------

posted @ 2020-04-07 20:21  它的眼角开过光  阅读(1300)  评论(0编辑  收藏  举报