/*
使用函数处理数据
*/
substr();
SUBSTR();
substring();
SUBSTRING(); --截取字符
SELECT SUBSTRING(prod_name,2,6) FROM Products ;
SELECT prod_name FROM Products;
select convert(varchar,prod_price) from Products;
select * from Products;
CONVERT(); --转换 数据类型转换
convert();
now();
select GETDATE() -- 获取当前日期时间
select * from Products where GETDATE()=GETDATE();
UPPER() -- 将字符串转换为大写
SELECT UPPER(Products.prod_name) FROM Products;
select LEFT(Products.prod_name,2) from Products
select RIGHT(Products.prod_name,3) from Products;
lower()
select LOWER(prod_name) from Products; --转换字符串为小写 lower()
select UPPER(PROD_NAME) FROM Products; --转换字符串为大写 upper()
select DATALENGTH(prod_name) from Products; -- datalength() DATALENGTH() 返回的是总数据长度 并不是当前列的数据长度
select LEN(prod_name) from Products; -- LEN() len() 返回参数值的数据长度。 当前列的数据长度 len 和 datalength 两种函数 length不属于函数
SELECT LTRIM(prod_NAME) FROM Products; --去除字符串左边的空格 LTRIM() 开头L是 left(左 L) L的首字母
SELECT RTRIM(PROD_NAME) FROM Products; --去除字符串右边的空格 RTRIM() 开头R是 right(右 R)R的首字母
select SOUNDEX(prod_name) from Products; -- 探测法:返回由四个字符组成的代码 第一个代码是字符串的首字母, 数字为0 。剩余字符安装soundex函数的规则返回对应数值。
select cust_name,cust_contact from Customers where SOUNDEX(cust_contact)=SOUNDEX('miqwael green');
select order_num from Orders where DATEPART(YY,order_date)=2012 ;
select order_num from Orders where order_date between ('2012-01-01') and ('2012-12-31'); --加上单引号 可以查询出想要的数据
select order_num from Orders where order_date between (2012-01-01) and (2012-12-31); --不加单引号 查询不出想要的数据
select order_num from Orders where order_date between convert(int,2012-01-01) and convert(int,2012-12-31); -- 查不到数据
select order_num from Orders where order_date between convert(varchar,'2012-01-01') and convert(varchar,'2012-12-31'); --查得到数据
select prod_name from Products;
select ABS(prod_price) from Products; --返回数值的绝对值
select COS(prod_price) from Products; --
select EXP(prod_price) from Products;
SELECT PI(); --返回圆周率
select SIN(prod_price) from Products;
select SQRT(prod_price) from Products;
select TAN(prod_price) from Products;