SqlServer function usage

SqlServer removes duplicate queries for the first data:
  select ID from(
    select *, row_number() over (partition by SynCode order by id) as RowNum  from syn_table
  ) s  where s.RowNum = 1
 
SqlServer merge rows separated by commas:
  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 string in query
  DECLARE @UnitCode VARCHAR(50)='1,2,3'

  select * from dbo.Table1 where PATINDEX('%,'+RTRIM(TestNo)+',%',','+@UnitCode+',')>0

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325009725&siteId=291194637