预览模式: 普通 | 列表

对粉尘螨、屋尘螨过敏应注意什么?怎么治疗?

螨虫在湿度低于15%的干燥环境中就会死亡,在低温的环境中无法进一步繁殖。因此,即使现在它们对传统杀虫剂越来越具备适应性和抵抗力,以至无法被彻底杀灭,但搞好家庭和个人清洁卫生,仍不失为经济有效的除虫办法。
具体方法是经常保持居室和工作室的通风干燥,勤换洗衣服、被褥,定期曝晒、拍打被褥、床垫、枕芯、草席和地毯等物品。在春夏季,经常将草、竹席放在太阳下晾晒、拍打,或用75%乙醇擦拭,或将樟脑精块等芳香驱虫品放在床垫或席子下。经常用吸尘器吸除地毯上的灰尘,还可以用除虫菊酯醚类的除虫剂喷洒在地毯上,或用棉纱蘸松节油擦拭地毯。最好不要让宠物进卧室,并定期给宠物洗澡和驱虫、消毒。




下面是具体资料
主讲:魏庆宇 博士

减少生活和工作和环境中尘螨的含量对尘螨过敏患者来说非常重要,可以通过控制措施减少吸入尘螨鳞片及排泄物的量,来预防和减轻发病,减少发病次数。尘螨最适宜的生存条件是温度17~30℃,相对湿度75%~80%,屋尘螨以人体或动物脱落的皮屑为食,在床铺上和卧室地毯中繁殖较快,一个人每日产生0.7克左右皮屑。粉尘螨以...

查看更多...

Tags: 粉尘螨 屋尘螨

分类:Living | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 8

ip地址转数值

 

ASP/Visual Basic代码
  1. Function ChangeIP(ip)  
  2.     strIP=Split(ip,".")  
  3.     ChangeIP=int(strIP(0))*16777216 + int(strIP(1)) *65536 + int(strIP(2))*256 +int(strip(3))  
  4. End Function   
SQL代码
  1. create function dbo.f_ip2int(  
  2. @ip char(15)  
  3. )returns bigint  
  4. as  
  5. begin  
  6.     declare @re bigint  
  7.     set @re=0  
  8.     select @re=@re+left(@ip,charindex('.',@ip+'.')-1)*id  
  9.         ,@ip=stuff(@ip,1,charindex('.',@ip+'.'),'')  
  10.     from(  
  11.         select id=cast(16777216 as bigint)  
  12.         union all select 65536  
  13.         union all select 256  
  14.         union all select 1)a  
  15.     return(@re)  
  16. end  

查看更多...

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

(C# )Ftp的操作

C#代码
  1. using System.IO;  
  2. using System.Net;  
  3. using System.Text;  
  4. using System.Diagnostics;  
  5. using System.Text.RegularExpressions;  
  6.   
  7.     //从ftp上下载文件  
  8.     private void Download(string filePath, string ImageSrc, string ImageName, string ftpServerIP, string   
  9.    
  10.   
  11. ftpUserName, string ftpPwd)  
  12.     {  
  13.         if (!Directory.Exists(filePath))  
  14.         {  
  15.             Directory.CreateDirectory(filePath);  
  16.         }  
  17.         using (FileStream OutputStream = new FileStream(filePath + "\\" + ImageName, FileMode.Create)) 
  18.         { 
  19.             FtpWebRequest ReqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/" +   
  20.   
  21. ImageSrc));  
  22.   
  23.             ReqFTP.Method = WebRequestMethods.Ftp.DownloadFile;  
  24.   
  25.             ReqFTP.UseBinary = true;  
  26.   
  27.             ReqFTP.Credentials = new NetworkCredential(ftpUserName, ftpPwd);  
  28.   
  29.             using (FtpWebResponse response = (FtpWebResponse)ReqFTP.GetResponse())  
  30.             {  
  31.   
  32.                 using (Stream FtpStream = response.GetResponseStream())  
  33.                 {  
  34.   
  35.                     long Cl = response.ContentLength;  
  36.   
  37.                     int bufferSize = 2048;  
  38.   
  39.                     int readCount;  
  40.   
  41.                     byte[] buffer = new byte[bufferSize];  
  42.   
  43.                     readCount = FtpStream.Read(buffer, 0, bufferSize);  
  44.   
  45.                     while (readCount > 0)  
  46.                     {  
  47.                         OutputStream.Write(buffer, 0, readCount);  
  48.   
  49.                         readCount = FtpStream.Read(buffer, 0, bufferSize);  
  50.                     }  
  51.   
  52.                     FtpStream.Close();  
  53.                 }  
  54.   
  55.                 response.Close();  
  56.   
  57.             }  
  58.   
  59.             OutputStream.Close();  
  60.         }  
  61.   
  62.     }  
  63.         //从服务器上传文件到FTP上  
  64.     private void UploadSmall(string sFileDstPath, string FolderName, string ftpServerIP, string ftpUserName,   
  65.   
  66. string ftpPwd)  
  67.     {  
  68.   
  69.         FileInfo fileInf = new FileInfo(sFileDstPath);  
  70.   
  71.         FtpWebRequest reqFTP;  
  72.   
  73.         reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/" + FolderName + "/" +   
  74.   
  75. fileInf.Name));  
  76.   
  77.         reqFTP.Credentials = new NetworkCredential(ftpUserName, ftpPwd);  
  78.   
  79.         reqFTP.KeepAlive = false;  
  80.   
  81.         reqFTP.Method = WebRequestMethods.Ftp.UploadFile;  
  82.   
  83.         reqFTP.UseBinary = true;  
  84.   
  85.         reqFTP.ContentLength = fileInf.Length;  
  86.   
  87.         int buffLength = 2048;  
  88.   
  89.         byte[] buff = new byte[buffLength];  
  90.   
  91.         int contentLen;  
  92.   
  93.         using (FileStream fs = fileInf.OpenRead())  
  94.         {  
  95.   
  96.             using (Stream strm = reqFTP.GetRequestStream())  
  97.             {  
  98.   
  99.                 contentLen = fs.Read(buff, 0, buffLength);  
  100.   
  101.                 while (contentLen != 0)  
  102.                 {  
  103.   
  104.                     strm.Write(buff, 0, contentLen);  
  105.   
  106.                     contentLen = fs.Read(buff, 0, buffLength);  
  107.                 }  
  108.   
  109.                 strm.Close();  
  110.             }  
  111.   
  112.             fs.Close();  
  113.         }  
  114.   
  115.     }  
  116.     //删除服务器上的文件  
  117.     private void DeleteWebServerFile(string sFilePath)  
  118.     {  
  119.         if (File.Exists(sFilePath))  
  120.         {  
  121.             File.Delete(sFilePath);  
  122.         }  
  123.     }  
  124.     //删除FTP上的文件  
  125.     private void DeleteFtpFile(string[] IName, string FolderName, string ftpServerIP, string ftpUserName, string   
  126.   
  127. ftpPwd)  
  128.     {  
  129.         foreach (string ImageName in IName)  
  130.         {  
  131.             string[] FileList = GetFileList(FolderName, ftpServerIP, ftpUserName, ftpPwd);  
  132.             for (int i = 0; i < FileList.Length; i++)  
  133.             {  
  134.                 string Name = FileList[i].ToString();  
  135.                 if (Name == ImageName)  
  136.                 {  
  137.                     FtpWebRequest ReqFTP;  
  138.   
  139.                     ReqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/" +   
  140.   
  141. FolderName + "/" + ImageName)); 
  142.  
  143.                     ReqFTP.Credentials = new NetworkCredential(ftpUserName, ftpPwd); 
  144.  
  145.                     ReqFTP.KeepAlive = false; 
  146.  
  147.                     ReqFTP.Method = WebRequestMethods.Ftp.DeleteFile; 
  148.  
  149.                     ReqFTP.UseBinary = true; 
  150.  
  151.                     using (FtpWebResponse Response = (FtpWebResponse)ReqFTP.GetResponse()) 
  152.                     { 
  153.  
  154.                         long size = Response.ContentLength; 
  155.  
  156.                         using (Stream datastream = Response.GetResponseStream()) 
  157.                         { 
  158.  
  159.                             using (StreamReader sr = new StreamReader(datastream)) 
  160.                             { 
  161.  
  162.                                 sr.ReadToEnd(); 
  163.  
  164.                                 sr.Close(); 
  165.                             } 
  166.  
  167.                             datastream.Close(); 
  168.                         } 
  169.  
  170.                         Response.Close(); 
  171.                     } 
  172.                 } 
  173.             } 
  174.  
  175.         } 
  176.  
  177.     } 
  178.     //检查文件是否存在 
  179.     public string[] GetFileList(string FolderName, string ftpServerIP, string ftpUserName, string ftpPwd) 
  180.     { 
  181.         string[] downloadFiles; 
  182.  
  183.         StringBuilder result = new StringBuilder(); 
  184.  
  185.         FtpWebRequest reqFTP; 
  186.         try 
  187.         { 
  188.             reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/" + FolderName +   
  189.   
  190. "/")); 
  191.  
  192.             reqFTP.UseBinary = true; 
  193.  
  194.             reqFTP.Credentials = new NetworkCredential(ftpUserName, ftpPwd); 
  195.  
  196.             reqFTP.Method = WebRequestMethods.Ftp.ListDirectory; 
  197.  
  198.             WebResponse response = reqFTP.GetResponse(); 
  199.  
  200.             StreamReader reader = new StreamReader(response.GetResponseStream()); 
  201.  
  202.             string line = reader.ReadLine(); 
  203.  
  204.             while (line != null) 
  205.             { 
  206.                 result.Append(line); 
  207.  
  208.                 result.Append("\n"); 
  209.  
  210.                 line = reader.ReadLine(); 
  211.             } 
  212.             // to remove the trailing '\n'         
  213.             result.Remove(result.ToString().LastIndexOf('\n'), 1); 
  214.  
  215.             reader.Close(); 
  216.  
  217.             response.Close(); 
  218.  
  219.             return result.ToString().Split('\n'); 
  220.         } 
  221.         catch (Exception ex) 
  222.         { 
  223.             downloadFiles = null; 
  224.             return downloadFiles; 
  225.         } 
  226.     } 
  227.     //从客户端上传文件到FTP上 
  228.     private void UploadFtp(HttpPostedFile sFilePath, string filename, string FolderName, string ftpServerIP,  
  229.  
  230. string ftpUserName, string ftpPwd) 
  231.     { 
  232.         //获取的服务器路径 
  233.         //FileInfo fileInf = new FileInfo(sFilePath); 
  234.  
  235.         FtpWebRequest reqFTP; 
  236.  
  237.         reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/" + FolderName + "/" +   
  238.   
  239. filename));  
  240.   
  241.         reqFTP.Credentials = new NetworkCredential(ftpUserName, ftpPwd);  
  242.   
  243.         reqFTP.KeepAlive = false;  
  244.   
  245.         reqFTP.Method = WebRequestMethods.Ftp.UploadFile;  
  246.   
  247.         reqFTP.UseBinary = true;  
  248.   
  249.         reqFTP.ContentLength = sFilePath.ContentLength;  
  250.         //设置缓存  
  251.         int buffLength = 2048;  
  252.   
  253.         byte[] buff = new byte[buffLength];  
  254.   
  255.         int contentLen;  
  256.   
  257.         using (Stream fs = sFilePath.InputStream)  
  258.         {  
  259.   
  260.             using (Stream strm = reqFTP.GetRequestStream())  
  261.             {  
  262.   
  263.                 contentLen = fs.Read(buff, 0, buffLength);  
  264.   
  265.                 while (contentLen != 0)  
  266.                 {  
  267.   
  268.                     strm.Write(buff, 0, contentLen);  
  269.   
  270.                     contentLen = fs.Read(buff, 0, buffLength);  
  271.                 }  
  272.   
  273.                 strm.Close();  
  274.             }  
  275.   
  276.             fs.Close();  
  277.         }  
  278.   
  279.     }  
  280.     //创建目录  
  281.     private void CreateDirectory(string FolderName, string ftpServerIP, string ftpUserName, string ftpPwd)  
  282.     {  
  283.         //创建日期目录  
  284.         try  
  285.         {  
  286.             FtpWebRequest reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/" +   
  287.   
  288. FolderName));  
  289.   
  290.             reqFTP.UseBinary = true;  
  291.   
  292.             reqFTP.Credentials = new NetworkCredential(ftpUserName, ftpPwd);  
  293.   
  294.             reqFTP.KeepAlive = false;  
  295.   
  296.             reqFTP.Method = WebRequestMethods.Ftp.MakeDirectory;  
  297.   
  298.             FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();  
  299.         }  
  300.         catch  
  301.         {  
  302.             ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('系统忙,请稍后再 
  303.  
  304. 试!');location.href=location.href;</script>"); 
  305.         } 
  306.     } 
  307.     //检查日期目录和文件是否存在 
  308.     private static Regex regexName = new Regex(@"[^\s]*$", RegexOptions.Compiled); 
  309.     private bool CheckFileOrPath(string FolderName, string ftpServerIP, string ftpUserName, string ftpPwd) 
  310.     { 
  311.         //检查一下日期目录是否存在 
  312.         FtpWebRequest reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/"));  
  313.   
  314.         reqFTP.UseBinary = true;  
  315.   
  316.         reqFTP.Credentials = new NetworkCredential(ftpUserName, ftpPwd);  
  317.   
  318.         reqFTP.Method = WebRequestMethods.Ftp.ListDirectoryDetails;  
  319.   
  320.         Stream stream = reqFTP.GetResponse().GetResponseStream();  
  321.   
  322.         using (StreamReader sr = new StreamReader(stream))  
  323.         {  
  324.             string line = sr.ReadLine();  
  325.   
  326.             while (!string.IsNullOrEmpty(line))  
  327.             {  
  328.                 GroupCollection gc = regexName.Match(line).Groups;  
  329.                 if (gc.Count != 1)  
  330.                 {  
  331.                     throw new ApplicationException("FTP 返回的字串格式不正确");  
  332.                 }  
  333.   
  334.                 string path = gc[0].Value;  
  335.                 if (path == FolderName)  
  336.                 {  
  337.                     return true;  
  338.                 }  
  339.   
  340.                 line = sr.ReadLine();  
  341.             }  
  342.         }  
  343.   
  344.         return false;  
  345.   
  346.     }  
  347. }  

 

分类:.Net | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 17

通过WebService上传图片

C#代码
  1. WebService部分:  
  2. /// <summary>  
  3.     /// 保存文件到远程服务器  
  4.     /// </summary>  
  5.     /// <param name="FileByteArray">待转换字节数组</param>  
  6.     /// <param name="FileLength">字节长度</param>  
  7.     /// <param name="SaveToUrl">保存路径</param>  
  8.     /// <returns>返回是否执行成功</returns>  
  9.     [WebMethod(Description = "保存文件到远程服务器.")]  
  10.     public bool SaveFile(byte[] FileByteArray,int FileLength, string SaveToUrl)  
  11.     {  
  12.         try  
  13.         {  
  14.             FileStream fs = new FileStream(SaveToUrl, FileMode.OpenOrCreate, FileAccess.Write);  
  15.             fs.Write(FileByteArray, 0, FileLength);  
  16.             fs.Close();  
  17.         }  
  18.         catch {  
  19.             return false;  
  20.         }  
  21.         return true;  
  22.     }      
  23.   
  24. 调用部分:  
  25. protected void Button1_Click(object sender, EventArgs e)  
  26.     {  
  27.         MangerPhoto.Service mp = new MangerPhoto.Service();  
  28.         Response.Write(mp.SaveFile(getByte(), FileUpload1.PostedFile.ContentLength, "C:\\vv.jpg"));  
  29.     }  
  30.   
  31.     private byte[] getByte() {//获得转化后的字节数组  
  32.         //得到用户要上传的文件名  
  33.         string strFilePathName = FileUpload1.PostedFile.FileName;  
  34.         string strFileName = Path.GetFileName(strFilePathName);  
  35.         int FileLength = FileUpload1.PostedFile.ContentLength;  
  36.         //上传文件  
  37.         Byte[] FileByteArray = new Byte[FileLength]; //图象文件临时储存Byte数组  
  38.         Stream StreamObject = FileUpload1.PostedFile.InputStream; //建立数据流对像  
  39.         //读取图象文件数据,FileByteArray为数据储存体,0为数据指针位置、FileLnegth为数据长度  
  40.         StreamObject.Read(FileByteArray, 0, FileLength);  
  41.         return FileByteArray;  
  42.     }  

 

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

新劳动法案例:合同期内辞职的补偿金问题

  问:我于2007年12月5日正式上班,在签劳动合同前公司表示,按照2008年新施行的劳动合同法规定,将与我签订新的劳动合同,合同期限为3年,试用期6个月。我想知道,劳动合同签这么久合理吗?如果3年内辞职需要承担违约金呢?另外,合同期内辞职能得到经济补偿金吗?

  答:公司如果在2008年1月底之前不与张先生签订《劳动合同》是违法的,公司就应该支付双倍的工资,而且签订劳动合同时应告知张先生相关的权利和义务。

  合同期限3年是合理的,试用期6个月也是合法的。《劳动合同法》的颁布就是要求企业与员工签订劳动合同,而且希望企业与员工多签中长期劳动合同,这些规定就是为使我们国家的劳动用工规范化、合理化。

  如果想在合同期内辞职,按照法律规定不会承担违约金,但是应该提前1个月向公司提出辞职申请,并办理《离职交接》。

  如果在合同期内提出辞职,按照法律规定将不会得到经济补偿金。根据《劳动合同法》的规定:由劳动者提出解除劳动合同的,用人单位有权不支付经济补偿金。
分类:Living | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 20

ASP.NET Impersonation

解决上传到局域网其它电脑文件权限问题:
http://msdn.microsoft.com/en-us/library/aa292118.aspx

<identity impersonate="true"
          userName="domain\user"
          password="password" /&...

查看更多...

分类:.Net | 固定链接 | 禁止评论 | 引用: 0 | 查看次数: 23

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 | 固定链接 | 评论: 3 | 引用: 0 | 查看次数: 54

行列互转总结

 

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 | 查看次数: 68