龙之家园  
我的博客我做主!
1.EXCEL中的函数:
=CONCATENATE("INSERT INTO  [SnatchDB].[dbo].[Snatch_Mission]([F_ID],[MissionName],[BeginURL],[NewsLabel]) VALUES(",Y2,",'",D2,"','",E2,"','",C2,"'",")")
2.SQL2005中清空日志的方法:
第一步: 先备份整个数据库以备不测
第二步: 备份结束后,在Query Analyzer中执行如下的语句: exec sp_detach_db yourDBName,true --卸除这个DB在MSSQL中的注册信息
第三步: 到日志的物理文件所在的目录中去删除该日志文件或者将该日志文件移出该目录
第四步: 在Query Analyzer中执行如下的语句: exec sp_attach_single_file_db yourDBName,'d:\mssql7\data\yourDBName_data.mdf' -- 以单文件的方式注册该DB,如果成功则MSSQL将自动为这个DB生成一个500K的日志文件
3.datalist奇偶行替换显示颜色,
       if (e.Row.RowType == DataControlRowType.DataRow)//判定当前的行是否属于datarow类型的行
         {
             //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色
             e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#d3d3d3',this.style.fontWeight='';");
             //当鼠标离开的时候 将背景颜色还原的以前的颜色
             e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
         }
         //单击行改变行背景颜色
         if (e.Row.RowType == DataControlRowType.DataRow)
         {
             e.Row.Attributes.Add("onclick", "this.style.backgroundColor='Burlywood'; this.style.color='buttontext';this.style.cursor='default';");
         }
4.把A表中的categoryID改换为B表中的newcategoryID:
    update A set A.categoryID=B.newcategoryID from A join B on A.categoryid=B.oldCategoryid
5.有A,B两表,A表中字段TYPE(产品型号),B表中有字段P_NAME(产品名称,名称中包含产品型号),现将两个字段like查询,找出P_NAME中包含的型号,把A表中相对应的ID写入B表中的P_ID中:
update B
set P_ID=A.ID
from B,A
where charindex(A.TYPE,B.P_NAME)>0      ( 用charindex函数判断type是否在p_name中where charindex(a.type1,b.p_name)>0)

update b set pid=(select id from a where b.p_name like '%'+a.type+'%')

6.两个表相联接查询,A表和B表,A表中有categoryID,B表中有oldcategoryID,现在的做法是从A表中找到其categoryID与B表中oldcategoryID不一样的数据!并按A表中的categoryID分组,并去除重复的categoryID.也就是每个categoryID的分类只显示一条:
SELECT categoryID FROM A
WHERE NOT EXISTS(SELECT 1 FROM B WHERE A.categoryID=B.oldcategoryID)
GROUP BY categoryID
posted on 2007-06-26 12:06  zhengfeng  阅读(156)  评论(0)    收藏  举报