sql isnullº¯ÊýµÄʹÓÃ
sql isnullº¯ÊýµÄʹÓÃ
ISNULL
ʹÓÃÖ¸¶¨µÄÌæ»»ÖµÌæ»» NULL¡£
Óï·¨
ISNULL ( check_expression , replacement_value )
²ÎÊý
check_expression
½«±»¼ì²éÊÇ·ñΪ NULLµÄ±í´ïʽ¡£check_expression ¿ÉÒÔÊÇÈκÎÀàÐ͵ġ£
replacement_value
ÔÚ check_expression Ϊ NULLʱ½«·µ»ØµÄ±í´ïʽ¡£replacement_value ±ØÐëÓë check_expresssion ¾ßÓÐÏàͬµÄÀàÐÍ¡£
·µ»ØÀàÐÍ
·µ»ØÓë check_expression ÏàͬµÄÀàÐÍ¡£
×¢ÊÍ
Èç¹û check_expression ²»Îª NULL£¬ÄÇô·µ»Ø¸Ã±í´ïʽµÄÖµ£»·ñÔò·µ»Ø replacement_value¡£
ʾÀý
A. ½« ISNULL Óë AVG Ò»ÆðʹÓÃ
ÏÂÃæµÄʾÀý²éÕÒËùÓÐÊéµÄƽ¾ù¼Û¸ñ£¬ÓÃÖµ $10.00 Ìæ»» titles ±íµÄ price ÁÐÖеÄËùÓÐ NULL ÌõÄ¿¡£
USE pubs
GO
SELECT AVG(ISNULL(price, $10.00))
from titles
GO
ÏÂÃæÊǽá¹û¼¯£º
--------------------------
14.24
(1 row(s) affected)
B. ʹÓà ISNULL
ÏÂÃæµÄʾÀýΪ titles ±íÖеÄËùÓÐÊéÑ¡ÔñÊéÃû¡¢ÀàÐͼ°¼Û¸ñ¡£Èç¹ûÒ»¸öÊéÃûµÄ¼Û¸ñÊÇ NULL£¬ÄÇôÔÚ½á¹û¼¯ÖÐÏÔʾµÄ¼Û¸ñΪ 0.00¡£
USE pubs
GO
SELECT SUBSTRING(title, 1, 15) AS Title, type AS Type,
ISNULL(price, 0.00) AS Price
from titles
GO
ÏÂÃæÊǽá¹û¼¯£º
Title Type Price
--------------- ------------ --------------------------
The Busy Execut business 19.99
Cooking with Co business 11.95
You Can Combat business 2.99
Straight Talk A business 19.99
Silicon Valley mod_cook 19.99
The Gourmet Mic mod_cook 2.99
The Psychology UNDECIDED
ÔÎĵØÖ·£ºhttp://blog.chinaunix.net/u/15793/showart_183147.html
Ïà¹ØÎĵµ£º
Ò»¡¢»ù´¡
1¡¢ËµÃ÷£º´´½¨Êý¾Ý¿â
CREATE DATABASE database-name
2¡¢ËµÃ÷£ºÉ¾³ýÊý¾Ý¿â
drop database dbname
3¡¢ËµÃ÷£º±¸·Ýsql server
--- ´´½¨ ±¸·ÝÊý¾ÝµÄ device
USE master
EXEC sp_addumpdevice 'disk', 'testBack', 'c:\mssql7backup\MyNwind_1.dat'
--- ¿ªÊ¼ ±¸·Ý
BACKUP DATABASE pubs TO testBack
4¡¢Ëµ ......
±¾ÎĵØÖ·£ºhttp://qzone.qq.com/blog/236000056-1217427602
ÎÞ·¨Á¬½Óµ½·þÎñÆ÷
·þÎñÆ÷£ºÏûÏ¢18452, ¼¶±ð16£¬×´Ì¬1
[Microsoft][ODBC SQLServer Driver][SQL Server]Óû§‘sa’µÇ½ʧ°Ü¡£ÔÒò£ºÎ´ÓëÐÅÈÎSQL ServerÁ¬½ÓÏà¹ØÁª
¸Ã´íÎó²úÉ ......
ÔÚSQL ServerÖÐʹÓÃNewID()·½·¨²úÉúËæ»ú¼¯
ÀýÈ翼ÊÔϵͳÖеÄËæ»ú³öÌâ
¸Õ¿ªÊ¼Ïëµ½µÄÊÇRandomÀà
µ«ÊÇRandomЧÂÊÓеãµÍ
ºóÀ´Ïëµ½ÁËÔÚÊý¾Ý¿âÀïµÄnewid()
ÓÚÊDzÉÓÃÁËϱ߷½·¨£º
select top 5 * from tablename order by newid()
Ôڴ˱ê¼ÇһϠ......
CREATE PROCEDURE dbo.UspOutputData
@tablename sysname
AS
declare @column varchar(1000)
declare @columndata varchar(1000)
declare @sql varchar(4000)
declare @xtype tinyint
declare @name sysname
declare @objectId int
declare @objectname sysname
declare @ident int
set nocount on
......