易截截图软件、单文件、免安装、纯绿色、仅160KB

某外企SQL Server面試題

--> Title  : 某外企SQL Server面試題
--> Author : wufeng4552
--> Date   : 2010-1-15
Question 1:Can you use a batch SQL or store procedure to calculating the Number of Days in a Month
Answer 1:找出当月的天数
select datepart(dd,dateadd(dd,-1,dateadd(mm,1,cast(cast(year(getdate()) as varchar)+'-'+cast(month(getdate()) as varchar)+'-01' as datetime))))
Question2:Can you use a SQL statement to calculating it!
How can I print "10 to 20" for books that sell for between $10 and $20,"unknown" for books whose price is null, and "other" for all other prices?
Answer 2:
select bookid,
       bookname,
       price=case when price is null then 'unknown'
                  when  price between 10 and 20 then '10 to 20'
                  else price
             end
from books
Question3:Can you use a SQL statement to finding duplicate values!
How can I find authors with the same last name?You can use the table authors in datatabase pubs. I want to get the result as below:
Output:
au_lname                                 number_dups
---------------------------------------- -----------
Ringer                                   2
(1 row(s) affected)
Answer 3:
select au_lname,
        number_dups=count(1)
from authors
group by au_lname
Question4:Can you create a cro


相关文档:

SQL Server存储过程编写和优化措施

一、适合读者对象:数据库开发程序员,数据库的数据量很多,涉及到对SP(存储过程)的优化的项目开发人员,对数据库有浓厚兴趣的人。  
二、介绍:在数据库的开发过程中,经常会遇到复杂的业务逻辑和对数据库的操作,这个时候就会用SP来封装数据库操作。如果项目的SP较多,书写又没有一定的规范,将会影响以后的系统维护 ......

sql关于between的用法改进

最近用到日期范围的查询,用到了between,但是发现如果日期带时间的话,BETWEEN '2010-1-4' AND 
       '2010-1-4'这样的语句是查不到数据的,后来想到了一种改进方法,供大家参考。
如下:
BETWEEN '2010-1-4' AND DATEADD(day, 1, '2010-1-4')
用了DATEADD以后,效果很不错 ......

SQL语句导入导出

SQL语句导入导出
/******* 导出到excel
EXEC master..xp_cmdshell 'bcp SettleDB.dbo.shanghu out c:\temp1.xls -c -q -S"GNETDATA/GNETDATA" -U"sa" -P""'
/*********** 导入Excel
SELECT *
from OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
'Data Source="c:\test.xls";User ID=Admin;Password=;Extended propert ......

SQL语句优化

对同一张表进行两种方式查询(结果集相同):
case1 查询条件:包括计算机名,昵称,添加时间等等一些限制条件字段。而且需联表查询别的表
查询数据量:             100万       200万
单纯执行SQL语句所需时间:31毫秒&nbs ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号