SQL编程语句
视图
视图就是我们查询出来的虚拟表
创建视图:create view 视图名
as
SQL查询语句,分组,排序,in 等都不能写
视图的用法: select * from 视图名
SQL编程
定义变量:declare @变量名 数据类型 declare @a int
变量赋值:set @变量名 = 值 set @a=10
select @a --直接打印在结果框中
set @a = 10 --也是赋值,不打印
select @a; --打印在结果集中
print @a; --打印在消息框中
-----------------------------------------------------
查汽车表中名称含有宝马两个字的
declare @name varchar(20)
set @name='宝马'
select * from car where Name like '%'+@name+'%'
查汽车表中所有汽车的平均值并输出
declare @price decimal(10,4)
select @price = AVG(Price) from Car
print '所有汽车的平均价格为:'+cast(@price as varchar(20))
-----------------------------------------------------
if ... else 的用法,if后面没有小括号,花括号用begin end 替代
if 判断条件
begin
要执行的语句
end
else
begin
要执行的语句
end
-----------------------------------------------------
declare @a int
declare @b int
declare @c int
set @a =10;
set @b =5;
if @a>@b
begin
set @c = @a + @b;
end
else
begin
set @c = @a - @b;
end
print @c
-----------------------------------------------------
C#里的Switch case 变形到数据库里用法
declare @ccname varchar(20)
set @ccname = '宝马'
select * from Car where Name like
case --switch...case的开头
when @ccname='宝马' then '%宝马%'
when @ccname='奥迪' then '%奥迪%'
else '%'
end --switch...case的结尾
-----------------------------------------------------
循环:
注意循环四要素
declare @str varchar(20)
set @str = '你好'
declare @i int
set @i = 1
while @i<=10
begin
print @str + cast (@i as varchar(20))
set @i = @i + 1
end
whie(条件)
{
循环体
}
-----------------------------------------------------
注意:语句结束之后不要写分号或逗号
最新文章
- 帆软报表FineReport中数据连接之Jboss配置JNDI连接
- resultset 对象获取行字段数据时报:java.sql.SQLException: Column &#39;id&#39; not found.
- List,Set,Map用法以及区别
- 【Python之路Day12】网络篇之Paramiko
- 放到u-boot/arch/arm/inlcude下面解压A20固件库制作笔记
- SD卡驱动分析(一)
- ubuntu 11.10 安装apache2 tomcat6
- 函数lock_rec_get_nth_bit
- HTML——表格table标签,tr或者td
- JavaScript--对象+函数
- HDU 3660 Alice and Bob&#39;s Trip
- 解决百度Ueditor编辑器表格不显示边框问题
- Bing必应(Yahoo雅虎)搜索引擎登录网站 - Blog透视镜
- gitLab添加ssh key
- wikioi 1034 家 实时动态的网络流量(费用流)
- 设置自己Eclipse代码风格(内部)
- 利用ZYNQ SOC快速打开算法验证通路(5)——system generator算法IP导入IP integrator
- Web程序报错:Error instantiating servlet
- easyui 信息提示
- python isinstance()方法的使用