SqlServer基礎

REVERSE(欄位) 反轉

CHARINDEX(篩選字符,欄位,[start])

例:CHARINDEX('/',ProImage,13) 從13位查詢/所在索引

SUBSTRING(欄位,start,end)

例:SUBSTRING(ProImage,0,CHARINDEX('/',ProImage,13)+1) 獲取ProImage欄位中從第一位到/所在位置(+1是因為索引從01開始)

REPLACE(欄位,字符,替換字符)

例:REPLACE(ProImage,SUBSTRING(ProImage,0,CHARINDEX('/',ProImage,13)+1),'')將從ProImage欄位獲取的字符替換成空

WITH AS实现循环获取parent部门

例:with Dep as ( select * from Department where DepartmentID='xxxx部门' union all select d.* from Department d inner join Dep p on d.ID=p.ParentID ) 

  select distinct DEPTNAME ESecondaryDept1, Z_DEPTNAME_LL CSecondaryDept1,DEPTNAME ESecondaryDept2,Z_DEPTNAME_LL CSecondaryDept2 from Employee where DepartmentID=(select top 1 DepartmentID from Dep where Description!='Dummy for System' )

 同一服务器上将A数据库表复制给B数据库表

select * into A.dbo.Dpa_Process from B.dbo.Dpa_Process

posted @ 2023-03-03 16:25  艺洁  阅读(18)  评论(0编辑  收藏  举报