预览模式: 普通 | 列表

JS取屏幕信息

JavaScript代码
  1. <script language="javascript">  
  2. function screenInfo(){  
  3.       var    s = "";  
  4.      s += "\r\n网页可见区域宽:"+ document.body.clientWidth;  
  5.      s += "\r\n网页可见区域高:"+ document.body.clientHeight;  
  6.      s += "\r\n网页可见区域宽:"+ document.body.offsetWidth    +" (包括边线的宽)";  
  7.      s += "\r\n网页可见区域高:"+ document.body.offsetHeight +" (包括边线的宽)";  
  8.      s += "\r\n网页正文全文宽:"+ document.body.scrollWidth;  
  9.      s += "\r\n网页正文全文高:"+ document.body.scrollHeight;  
  10.      s += "\r\n网页被卷去的高:"+ document.body.scrollTop;  
  11.      s += "\r\n网页被卷去的左:"+ document.body.scrollLeft;  
  12.      s += "\r\n网页正文部分上:"+ window.screenTop;  
  13.      s += "\r\n网页正文部分左:"+ window.screenLeft;  
  14.      s += "\r\n屏幕分辨率的高:"+ window.screen.height;  
  15.      s += "\r\n屏幕分辨率的宽:"+ window.screen.width;  
  16.      s += "\r\n屏幕可用工作区高度:"+ window.screen.availHeight;  
  17.      s += "\r\n屏幕可用工作区宽度:"+ window.screen.availWidth;  
  18.      alert(s);  
  19. }  
  20. screenInfo();  
  21. </script>  
  22.   
  23.   
  24. 注:我试过,如果在网页的前面有如下的W3C标准的头,上面的document.body.clientHeight和document.body.scrollTop是无效的  
  25. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  

 

分类:Javascript | 固定链接 | 评论: 1 | 引用: 0 | 查看次数: 22

行列互转总结

 

SQL代码
  1. --行列互转   
  2. /******************************************************************************************************************************************************   
  3. 以学生成绩为例子,比较形象易懂   
  4.   
  5. 整理人:中国风(Roy)   
  6.   
  7. 日期:2008.06.06   
  8. ******************************************************************************************************************************************************/   
  9.   
  10. --1、行互列   
  11. --> --> (Roy)生成測試數據   
  12.     
  13. if not object_id('Class'is null  
  14.     drop table Class   
  15. Go   
  16. Create table Class([Student] nvarchar(2),[Course] nvarchar(2),[Score] int)   
  17. Insert Class   
  18. select N'张三',N'语文',78 union all  
  19. select N'张三',N'数学',87 union all  
  20. select N'张三',N'英语',82 union all  
  21. select N'张三',N'物理',90 union all  
  22. select N'李四',N'语文',65 union all  
  23. select N'李四',N'数学',77 union all  
  24. select N'李四',N'英语',65 union all  
  25. select N'李四',N'物理',85    
  26. Go   
  27. --2000方法:   
  28. 动态:   
  29.   
  30. declare @s nvarchar(4000)   
  31. set @s=''  
  32. Select     @s=@s+','+quotename([Course])+'=max(case when [Course]='+quotename([Course],'''')+' then [Score] else 0 end)'  
  33. from Class group by[Course]   
  34. exec('select [Student]'+@s+' from Class group by [Student]')   
  35.   
  36.   
  37. 生成静态:   
  38.   
  39. select    
  40.     [Student],   
  41.     [数学]=max(case when [Course]='数学' then [Score] else 0 end),   
  42.     [物理]=max(case when [Course]='物理' then [Score] else 0 end),   
  43.     [英语]=max(case when [Course]='英语' then [Score] else 0 end),   
  44.     [语文]=max(case when [Course]='语文' then [Score] else 0 end)    
  45. from    
  46.     Class    
  47. group by [Student]   
  48.   
  49. GO   
  50. 动态:   
  51.   
  52. declare @s nvarchar(4000)   
  53. Select     @s=isnull(@s+',','')+quotename([Course]) from Class group by[Course]   
  54. exec('select * from Class pivot (max([Score]) for [Course] in('+@s+'))b')   
  55.   
  56. 生成静态:   
  57. select *    
  58. from    
  59.     Class    
  60. pivot    
  61.     (max([Score]) for [Course] in([数学],[物理],[英语],[语文]))b   
  62.   
  63. 生成格式:   
  64. /*   
  65. Student 数学          物理          英语          语文   
  66. ------- ----------- ----------- ----------- -----------   
  67. 李四      77          85          65          65   
  68. 张三      87          90          82          78   
  69.   
  70. (2 行受影响)   
  71. */   
  72.   
  73. ------------------------------------------------------------------------------------------   
  74. go   
  75. --加上总成绩(学科平均分)   
  76.   
  77. --2000方法:   
  78. 动态:   
  79.   
  80. declare @s nvarchar(4000)   
  81. set @s=''  
  82. Select     @s=@s+','+quotename([Course])+'=max(case when [Course]='+quotename([Course],'''')+' then [Score] else 0 end)'  
  83. from Class group by[Course]   
  84. exec('select [Student]'+@s+',[总成绩]=sum([Score])  from Class group by [Student]')--加多一列(学科平均分用avg([Score]))   
  85.   
  86. 生成动态:   
  87.   
  88. select    
  89.     [Student],   
  90.     [数学]=max(case when [Course]='数学' then [Score] else 0 end),   
  91.     [物理]=max(case when [Course]='物理' then [Score] else 0 end),   
  92.     [英语]=max(case when [Course]='英语' then [Score] else 0 end),   
  93.     [语文]=max(case when [Course]='语文' then [Score] else 0 end),   
  94.     [总成绩]=sum([Score]) --加多一列(学科平均分用avg([Score]))   
  95. from    
  96.     Class    
  97. group by [Student]   
  98.   
  99. go   
  100.   
  101. --2005方法:   
  102.   
  103. 动态:   
  104.   
  105. declare @s nvarchar(4000)   
  106. Select     @s=isnull(@s+',','')+quotename([Course]) from Class group by[Course] --isnull(@s+',','') 去掉字符串@s中第一个逗号   
  107. exec('select [Student],'+@s+',[总成绩] from (select *,[总成绩]=sum([Score])over(partition by [Student]) from Class) a   
  108. pivot (max([Score]) for [Course] in('+@s+'))b ')   
  109.   
  110. 生成静态:   
  111.   
  112. select    
  113.     [Student],[数学],[物理],[英语],[语文],[总成绩]    
  114. from    
  115.     (select *,[总成绩]=sum([Score])over(partition by [Student]) from Class) a --平均分时用avg([Score])   
  116. pivot    
  117.     (max([Score]) for [Course] in([数学],[物理],[英语],[语文]))b    
  118.   
  119. 生成格式:   
  120.   
  121. /*   
  122. Student 数学          物理          英语          语文          总成绩   
  123. ------- ----------- ----------- ----------- ----------- -----------   
  124. 李四      77          85          65          65          292   
  125. 张三      87          90          82          78          337   
  126.   
  127. (2 行受影响)   
  128. */   
  129.   
  130. go   
  131.   
  132. --2、列转行   
  133. --> --> (Roy)生成測試數據   
  134.     
  135. if not object_id('Class'is null  
  136.     drop table Class   
  137. Go   
  138. Create table Class([Student] nvarchar(2),[数学] int,[物理] int,[英语] int,[语文] int)   
  139. Insert Class   
  140. select N'李四',77,85,65,65 union all  
  141. select N'张三',87,90,82,78   
  142. Go   
  143.   
  144. --2000:   
  145.   
  146. 动态:   
  147.   
  148. declare @s nvarchar(4000)   
  149. select @s=isnull(@s+' union all ','')+'select [Student],[Course]='+quotename(Name,'''')--isnull(@s+' union all ','') 去掉字符串@s中第一个union all   
  150. +',[Score]='+quotename(Name)+' from Class'  
  151. from syscolumns where ID=object_id('Class'and Name not in('Student')--排除不转换的列   
  152. order by Colid   
  153. exec('select * from ('+@s+')t order by [Student],[Course]')--增加一个排序   
  154.   
  155. 生成静态:   
  156. select *    
  157. from (select [Student],[Course]='数学',[Score]=[数学] from Class union all    
  158. select [Student],[Course]='物理',[Score]=[物理] from Class union all    
  159. select [Student],[Course]='英语',[Score]=[英语] from Class union all    
  160. select [Student],[Course]='语文',[Score]=[语文] from Class)t    
  161. order by [Student],[Course]   
  162.   
  163. go   
  164. --2005:   
  165.   
  166. 动态:   
  167.   
  168. declare @s nvarchar(4000)   
  169. select @s=isnull(@s+',','')+quotename(Name)   
  170. from syscolumns where ID=object_id('Class'and Name not in('Student')    
  171. order by Colid   
  172. exec('select Student,[Course],[Score] from Class unpivot ([Score] for [Course] in('+@s+'))b')   
  173.   
  174. go   
  175. select    
  176.     Student,[Course],[Score]    
  177. from    
  178.     Class    
  179. unpivot    
  180.     ([Score] for [Course] in([数学],[物理],[英语],[语文]))b   
  181.   
  182. 生成格式:   
  183. /*   
  184. Student Course Score   
  185. ------- ------- -----------   
  186. 李四      数学      77   
  187. 李四      物理      85   
  188. 李四      英语      65   
  189. 李四      语文      65   
  190. 张三      数学      87   
  191. 张三      物理      90   
  192. 张三      英语      82   
  193. 张三      语文      78   
  194.   
  195. (8 行受影响)   
  196. */  

查看更多...

Tags: 行转列

分类:Sql Server | 固定链接 | 评论: 2 | 引用: 0 | 查看次数: 38

set lock_timeout 控制sql超时

sql 2005的begin try 和 begin catch 配合set lock_timeout,可以实现控制sql超时,例:

set lock_timeout 5000
declare @i int
declare @T table(data varchar(30))
set @i =0;
while ( @i < 100)
begin
        begin try
        insert @T select aa from tb where aa=1
     &...

查看更多...

分类:Sql Server | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 27
-----------------------------------------------------------------------
--组织测试数据,首先我们来组织category分类比较少的情况,分了体现这个差别,所以只分了两个分类
    drop table tb
    create table tb(id int identity primary key,category nvarchar(50),remark char(5000))


    declare @i int set @i=1
    while @i<=5000
  &nb...

查看更多...

Tags: sql优化

分类:Sql Server | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 30

发现有pr值了,我的是3

今天发现有pr值了,是3,呵呵
分类:Living | 固定链接 | 评论: 3 | 引用: 0 | 查看次数: 39
SQL Server 2000下将数据库直接备份到网络上其它计算机硬盘:

具体方法如下:

1.两台机器(数据库所在的机器和存放备份文件的机器)都需要建一个同名同密码的用户,方便起见,最好将这两个用户都直接归到管理员组下;
2.将数据库的启动帐户设置成刚才所建立的那个帐户,并重新开启SQL服务;
3.假设远程机器的IP是192.168.61.234,共享为默认共享f$,先用查询分析器登陆到本地的SQL服务器(用sa和信任模式都可以),在master下执行xp_cmdshell 'dir \\192.168.61.234\f$'看有没有结果,还是有报错的,如有报错,请根据错误提示检查;
4.执行以下备份语句可将数据库备份到远程硬盘上,以crm2k为例:
backup database crm2k to disk='\\192.168.61.234\f$\crm2k0722_2.dmp'
5.同时注意,一定要用“\\机器名或IP”不能用映射的盘符。查看更多...

分类:Sql Server | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 31

修复一个表

alter database 库名 set single_user
--dbcc checktable('表名',repair_rebuild)
dbcc checktable('表名',repair_allow_data_loss)
alter database 库名 set multi_user

查看更多...

分类:Sql Server | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 41

查询一个字符串位于哪个表

declare @searchstr nvarchar(500)
set @searchstr ='Publisher' --这里是你要查的字符内容
declare @t  varchar(255),@c  varchar(255)
create table # (name varchar(256),cols varchar(4000))
declare  table_cursor  cursor  for  
select  a.name,b.name  from  sysobjects  a,syscolumns &...

查看更多...

分类:Sql Server | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 43