1. 程式人生 > >sql server 基礎知識點總結(一)

sql server 基礎知識點總結(一)

select ISNULL(CAST(gonghao varchar(30),'sdsd')) from ren 解釋:將gonghao欄位的資料型別轉換成varchar(30)型別,在判斷gonghao型別是否為空,為空就替換為sdsd ISNULL:查詢,判斷如果是null值,則替換為其他 select isnull(name,'sdsd') from ren 解釋:判斷如果name欄位為空,則替換為sdsd TOP:查詢前5行的資料 select top 5 * from goods 查詢前百分之50的資料 select top 50 percent * from goods case
:類似於if else語句 例項1:區間用法 select g_ID,g_Name, 等級=case when g_Price<=2000 then '便宜' when g_Price<=4000 then '一般' else '奢侈' end from goods 例項2:等值用法 select g_ID,g_Name, 等級=case g_Price when 1500 then '便宜' when 2500 then '一般' else '奢侈' end
from goods 複製表 select top 5 * into newgoods from goods exists:包含一個查詢語句的查詢結果,有結果就返回true,沒結果就返回false if(exists(select * from Goods)) begin print('true執行這裡');