SqlServer函数使用

SqlServer去除重复查询第一条数据:
  select ID from(
    select *, row_number() over (partition by SynCode order by id) as RowNum  from syn_table
  ) s  where s.RowNum = 1
 
SqlServer合并行用逗号隔开:
  SELECT name,LEFT(ItemName,LEN(ItemName)-1) FROM (
  SELECT name,
    (SELECT name+',' FROM Base_BarcodeGroup c WHERE c.NAME=b.Name FOR XML PATH('')
  )AS ItemName  FROM  Base_BarcodeGroup as b  GROUP BY   name
     )AS a
 
SqlServer字符串in查询
  DECLARE @UnitCode VARCHAR(50)='1,2,3'
  select * from dbo.Table1 where PATINDEX('%,'+RTRIM(TestNo)+',%',','+@UnitCode+',')>0

 

Oreacle 批量插入:

Insert into 表名(ID,Name,Sex) 
select SEQ_Table_ID.nextVal,Name,Sex from (
   select  '张三'  name,'' Sex from dual  union 
   select  '李四'  name,'' Sex from dual   
)

 

posted @ 2018-04-28 10:08  坐拥百态  阅读(554)  评论(0编辑  收藏  举报