/******************************************************************************
**		Name: usp_cfg_GetFileByObjectIDAndType
**		Desc: 根据objectID和type获取附件
**
**              
**		Return Values:
** 				
**		Parameters:	
**		Auth:
**		Date:2008-10-28
*******************************************************************************/
ALTER proc [dbo].[usp_cfg_GetFileByObjectIDAndType]
	@ObjectID uniqueidentifier = 'E993BEFC-040F-47C4-BEB4-3782145341FA',
	@Type varchar(500) = null
as
begin
	SET NOCOUNT ON;

	select IsNull(Title,'') + 
	IsNull(Name,'') +
	IsNull(Description,'') +
	IsNull(KeyWord,'') __Keyword,

	NameSortExpression =				--特殊处理,为部务会议排序使用(按名称中的日期排序)
	case  when @ObjectID = '0BE5DF9E-02B0-44B8-BB0C-9633E26C888D' and isdate(replace(replace([name],'部务会备忘',''),'.doc',''))=1 then  cast(replace(replace([name],'部务会备忘',''),'.doc','') as datetime)
	      when @ObjectID = '0BE5DF9E-02B0-44B8-BB0C-9633E26C888D' and isdate(replace(replace([name],'部务会备忘',''),'.doc',''))=0 then  cast('1900-1-1' as datetime)
	      else UploadTime
	end,
	[FileID] ,
	[ObjectID] ,
	[Title] ,
	[Name] ,
	[Description] ,
	[KeyWord] ,
	[ContentType] ,
	--[Content] [image] NULL,
	[ContentLen] ,
	[Uploador] ,
	[UploadTime] ,
	[Status] ,
	[type] ,
	[Ranking],
	null as Content
	

	from tbl_cfg_file
	where objectid = @ObjectID
		and (
				charindex( cast(dbo.ufn_IsNullOrEmpty(@Type,Type) as varchar(8000)),cast(Type as varchar(500))) > 0  
			 or (dbo.ufn_IsNullOrEmpty(@Type,'') = dbo.ufn_IsNullOrEmpty(Type,''))
			 )   
end



set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON

  

/******************************************************************************
**		Name: ufn_IsNullOrEmpty
**		Desc: 同时判断null和空字符
**
**              
**		Return Values:null或空时,返回指定字符串,否则,返回自己
** 
**		Parameters:
**		Auth: 
**		Date: 2006-11-3
*******************************************************************************/
ALTER function ufn_IsNullOrEmpty(@expression sql_variant, @Replace sql_variant)
returns sql_variant
as
begin
   if( @expression = '' or @expression is null)
  return @Replace
 return @expression
end

  

sql_variant 这是一个不起眼,也用得不多的数据类型,但在某些场合下,可能很有用

一种数据类型,用于存储 SQL Server 2005 支持的各种数据类型(不包括 textntextimagetimestamp 和 sql_variant)的值。

 

换而言之,这个类型很容易让我们联想到VB编程中的variant类型,或者C#里面的object类型。它可以存放很多种格式。例如一个sql_variant列既可以存放数字,也可以存放文本。

当然,正因为这样的特性,它们在读取的时候必须进过一些转换,否则是不知道什么类型的。而且这种转换会有风险,这也就是所谓的类型不安全。

 

这种类型在使用上还有另外一些限制,请确认在使用之前对其进行必要的了解

 

一点都不意外,这个类型如果通过ORM框架(例如LINQ TO SQL)映射到客户程序中,会是一个object类型

sql case when then else end sql_variant_SQL