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

个人总结的几条比较有意思的sql语句


 
--------------------------------------------------------------------
-- 作者:张爱国
-- 日期:2010-01-23 15:00:17
-- 描述: 一些比较有意思的SQL语句
-- Version:
--    Microsoft SQL Server 2005 - 9.00.3042.00 (Intel X86)
--    Feb  9 2007 22:47:07
--    Copyright (c) 1988-2005 Microsoft Corporation
--    Express Edition on Windows NT 5.1 (Build 2600: Service Pack 3)
--------------------------------------------------------------------
--首先创建一个测试用的表
--一下语句中用到的表tb均指这个测试表
--1、你猜下面这条语句能得到什么结果,这个很常用
if object_id('tb') is not null
drop table tb
go select getdate()
create table tb(id int identity ,name varchar(10))
insert into tb select '张三'
union all select '李四'
union all select '王五'
union all select '赵六'
go
select * into ta from tb where 1<>1
--2、下面这条语句会报错吗?为什么,怎么修改才能让它输出 “正确” 这两个字
select case when 1>1 then 1
                        when 1=1 then '正确'
                        when 1<1 then 2
                end
--3、 怎么才能做到下面的三条同时执行得到的结果是命令已成功完成。
    --而不是select附近有语法错误
select
select 1
select
--4、 思考一下这个问题
--在master中建个表,在其它库里访问(同一服务器),不允许使用限定名,如何才能直接访问此表?
--5、 datalength() 返回用于表示任何表达式的字节数。
-- 你猜下面的结果会是什么?为什么
select datalength('1'),datalength(1),datalength(getdate()),datalength('2010-01-23 13:01:37.280')
--6、你可以试试下面的三个语句,为什么第一个会有语法错误,而第二个结果是正确的
--Ⅰ:
select * from tb ord


相关文档:

sql server存儲過程語法

-- 变量的声明,sql里面声明变量时必须在变量前加@符号
    DECLARE @I INT
-- 变量的赋值,变量赋值时变量前必须加set
    SET @I = 30
-- 声明多个变量
    DECLARE @s varchar(10),@a INT
-- Sql 里if语句
    IF 条件 BEGIN
   &nb ......

规划院培训费用统计查询的sql语句

create or replace view pxfy_view as
select t1.form_id,t1.reserve as mid,t1.feiyong,t.cjpxr_name as full_name,1 as pxlx,t1.topic,t1.identity,
     t1.begin_time as CREATEDATE,t1.end_time as completedate,pv.city,pv.DEPT_ID
     from wf_oa_pxnb_cjry t,WF_OA_PX ......

用C#读SQL SERVER到控制台的简单示例

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
//sqlserver身份验证
//string sqlconn = "ser ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号