常用的sql语句

Arthit 于 2024-08-11 发布

分组取第一条数据

select * from (select row_number() over(partition by ID order by ID) as rownum , * from table) as temp where temp.rownum = 1

分组后,以逗号分割拼接某字段

SELECT  SharerintName ,ProdCode = STUFF(( SELECT   ',' + CONVERT(nvarchar,Id) FROM AA_PrinterInfo a 
WHERE a.SharerintName = b.SharerintName FOR XML PATH('') ), 1,1, '') FROM AA_PrinterInfo b GROUP BY SharerintName

添加字段和描述

if COL_LENGTH('FC_JobTask','DeferCPIsFinished') is null
begin
alter table FC_JobTask add [DeferCPIsFinished] bit DEFAULT 0 NOT NULL
exec sp_addextendedproperty N'MS_Description', N'暂缓工序完工否', N'user', N'dbo', N'table', N'FC_JobTask', N'column', N'DeferCPIsFinished'
end

--更新描述
exec sp_updateextendedproperty N'MS_Description', N'状态:0 待审核', N'user', N'dbo', N'table', N'PO_SellOrderDetail', N'column', N'State'

分享一个MV

EXO组合的咆哮