摘要: with 建立臨時表with t1 as (select * from employee),t3 as( select top 1 t2.* from contract t2 ,t1 where t2.staffid=t1.staffid) select t1.staffid,t3.refnofrom t1,t3where t1.staffid=t3.staffid 阅读全文
posted @ 2011-06-10 11:18 左安 阅读(253) 评论(0) 推荐(0) 编辑
摘要: 停掉數據庫進程===declare @kill varchar(2000);set @kill = '';select @kill = @kill + 'kill ' + rtrim(spid) + ';' from master..sysprocesseswhere dbid = DB_ID('dbschema') and hostname <>'xx-PC';print @kill;exec (@kill); 阅读全文
posted @ 2011-06-10 11:15 左安 阅读(131) 评论(0) 推荐(0) 编辑
摘要: 執行字符串 sql==SET @SqlStr=N'delete from '+@batchdataTable+' where exists( select 1 from csps_batch t2 where batchid =t2.batchid and t2.lupdtime <=convert(datetime,'''+@dBefHusrKp+''',103) and status in (''A'',''D''))'; --select 阅读全文
posted @ 2011-06-10 10:40 左安 阅读(161) 评论(0) 推荐(0) 编辑
摘要: 查詢所有含有active 字段的log表===select table_name from information_schema.COLUMNS where COLUMN_NAME='active' and TABLE_CATALOG =(select TABLE_CATALOG from csps_system_param where pname='TABLE_CATALOG') and table_name like 'log%' 阅读全文
posted @ 2011-06-10 10:35 左安 阅读(204) 评论(0) 推荐(0) 编辑
摘要: SQL:通過function創建臨時表function作用:通過分隔符將字符串分割插入臨時表中。========ALTER function [dbo].[fn_splitStr](@str varchar(8000), @split varchar(10)) returns @t table(col varchar(100),rownum int identity(1,1)) as begin declare @splitLen int set @splitLen=len(@split) - 1 while charindex(@split, @str)>0 begin insert 阅读全文
posted @ 2011-06-10 10:27 左安 阅读(246) 评论(0) 推荐(0) 编辑