摘要: /*---查询SQL是否进程死锁exec ljj_SP_Sys_LockInfo@kill_lock_spid=0,@show_spid_if_nolock=1*/ALTER proc dbo.ljj_SP_Sys_LockInfo@kill_lock_spid bit=0, --是否殺掉鎖死的進程,1 殺掉, 0 僅顯示@show_spid_if_nolock bit=1 --如果沒有鎖死的進程...
阅读全文
摘要: /*---游標處理批量流程------------步驟1,建立表--檢查ProjectCode是否帶有特殊字符---步驟2---檢查所有簽核人帳號是否存在-----檢查導入簽核人是否正確(主要判斷數據是否為NULL)select distinct [級數] from dbo.[zlq_PCO1107] select * from dbo.[zlq_PCO1107] where [級數]=1 and...
阅读全文
摘要: --狀態多選--如果有狀態為A,B,C,D,E,F等區域,可多選.--則可用編碼A:1,B:2,C:4,D:8,E:16,F:32,G:64,m選擇A,D則為1+8=9,n選則B,C則為2+4=6--檢查m及n之所有選擇select 9|7--檢查m及n之交集select 9&7--如果判斷其所在區域可用DECLARE @I intset @I=9&7select 'A' wher...
阅读全文
摘要: -----------------------橫表轉豎表的範例1---------------------------------------------------臨時表列名查找-----------------------------SELECT OBJECT_ID('tempdb.qbrclient.#tt')select * from tempdb.dbo.syscolumnswhere ...
阅读全文
摘要: ------竪表轉橫表-------------------------------------------分組統計-----------------------------create table dbo.test(name varchar(50),nj varchar(50),km varchar(50),cj int)insert into dbo.test(name,nj,km,cj) v...
阅读全文
摘要: --Data Type數據類型/*new type:1.bigint--8B--int2.sql_variant--主要解決數據兼容問題而提出的數據類型,可存儲不同數據類型的數據。3.table--主要應用在編程環境中的數據類型,可以用臨時存儲從表格中取出的數據信息。int type1.bit= {0 | 1}--2B2.bigint {-2^63--2^63-1}--8B--max 3.inte...
阅读全文
摘要: --SQL 查詢屬性/*set nocount {on | off}--set on then no return rowcount set nocount onselect * from dbo.testljjprint @@rowcountset nocount offselect * from dbo.testljjprint @@rowcountset noexec {on | off}-...
阅读全文
摘要: --**************去除特殊的字符方法用replace()函數*****************************************declare @st varchar(100)select @st=',asdf,,,,,,,,,asdf, xx'+char(32)+'yy'+char(13)+'zz'+char(10)+'pp'+char(9)+'tt,'print @...
阅读全文
摘要: ------------統計User使用次數-----------------------------------------------------------select UpdateBy,count,day,convert(decimal(11,2),(count*1.0/(case when day=0 then 1 else day end))) as UseTime,beginDT,E...
阅读全文