参数是日期格式,如2011/6/1 0:00:00 ,会报错,用字符串则又提示数据类型不对,怎么做?

解决方案 »

  1.   

    有什么不对的?!
    declare @dt datetime
    set @dt='2011/6/1 0:00:00'
    select @dt
    /*
    -----------------------
    2011-06-01 00:00:00.000(1 行受影响)
    */
      

  2.   

    就用字符串赋值,传入后如果报错的话可以用Cast或者Convert转换类型
      

  3.   

    你可以where isdate('2011/6/1 0:00:00')=1判断下
      

  4.   

    比较两个日期是否同一天  datediff(day,date1,date2)=0
      

  5.   

    ESQL是什么 ?不是 MS-SQL吧?
      

  6.   

    如果是MSSQL 是很容易转换的
    convert(varchar(10),时间字段,120)
    得到的是 '2011-06-16'这样的数据
      

  7.   

    我用entityFrameWork 在c#代码中用esql查询 ,不是t-sql
      

  8.   


    Entity SQL 是 ADO.NET 实体框架 提供的 SQL 类语言,用于支持 实体数据模型 (EDM)。Entity SQL 可用于对象查询和使用 EntityClient 提供程序执行的查询。l           关键字Value关键字ESQL 提供了 SELECT VALUE 子句以跳过隐式行构造。SELECT VALUE 子句中只能指定一项。在使用这样的子句时,将不会对 SELECT 子句中的项构造行包装器,并且可生成所要形状的集合,例如:SELECT VALUE it FROM NorthwindEntities.Customers as itit关键字 it 出现在 ESQL 中, 查询对象的别名默认值 "it" 改成其他字符串,例如: "SELECT VALUE it FROM NorthwindEntities.Customers as it " 。 l           注释:Entity SQL 查询可以包含注释。注释行以两个短划线 (--) 开头。"SELECT VALUE it FROM NorthwindEntities.Customers as it -- this a comment "l           Select查询例如:SELECT VALUE it FROM NorthwindEntities.Customers as itl           参数参数是在esql之外定义的变量,每个参数都有名称和类型,参数名称在查询表达式中定义,并以@符号作为前缀。例如:Select VALUE c from NorthwindEntities.Customers as c where c.CustomerID=@customerIDl           聚合Enity SQL不支持 * ,所以esql不支持count(*),而是使用count(0),例如:Select count(0) from NorthwindEntities.Customers l           分页SKIP/LIMIT可以通过在 ORDER BY 子句中使用 SKIP 和 LIMIT 子子句执行物理分页。若要以确定的方式执行物理分页,应使用 SKIP 和 LIMIT。如果您只是希望以非确定的方式限制结果中的行数,则应使用 TOP。TOP 和 SKIP/LIMIT 是互斥的使用SKIP/LIMIT分页,esql代码如下:Select value c from NorthwindEntities.Customers as c order by c.CustomerID skip 0 limit 10l           TOPSELECT 子句可以在可选的 ALL/DISTINCT 修饰符之后具有可选的 TOP 子子句。TOP 子子句指定查询结果中将只返回第一组行。esql代码如下:Select top(10) c.CustomerID from NorthwindEntities.Customers as c order by c.CustomerIDl           NULL处理Null 文本与 Entity SQL 类型系统中的任何类型都兼容,可以使用cast进行类型转换,例如:select cast(c.region as string) from NorthwindEntities.Customers as c order by c.CustomerID limit 10其中, Nvarchar等可以成string,数字类型可以转成int32,其他的类型转换类似。如果无法完成转换,则将报异常。还有可以处理的方法有treat。 l           标识符Entity SQL 提供两种标识符:简单标识符和带引号的标识符简单标识符:Entity SQL 中的简单标识符是字母数字和下划线字符的序列。标识符的第一个字符必须是字母字符(a-z 或 A-Z)。带引号的标识符:带引号的标识符是括在方括号 ([]) 中的任何字符序列。带中文的部分,请使用方括号包括起来,否则会报如下异常信息:“简单标识符“中文”只能包含基本拉丁字符。若要使用UNICODE 字符,请使用转义标识符”正确的代码如下:Select c.CustomerID as [中文字符] from NorthwindEntities.Customers as c order by c.CustomerID skip 0 limit 10l           ROWEsql可使用row来构建匿名的结构类型的纪录。例如:SELECT VALUE row(p.ProductID as ProductID,p.ProductName as ProductName) FROM NorthwindEntities.Products as p order by p.ProductID LIMIT 10l           Key提取引用或实体表达式的键。如下esql语句,直接返回Customer表的主键:string esql = "SELECT value key(c) FROM NorthwindEntities.Customers as c order by c.CustomerID LIMIT 10"l           CreateRef/ref/derefCreateRef创建对实体集中的实体的引用。ref返回对实体实例的引用,之后就可以当作实体来访问其属性,esql语句如下:SELECT ref(c).CustomerID FROM NorthwindEntities.Customers as c order by c.CustomerID LIMIT 10deref运算符取消引用一个引用值,并生成该取消引用的结果。l           CASE语句:string esql = "using SqlServer;select case when len(trim(c.CustomerID))==0 then true else false end from NorthwindEntities.Customers as c order by c.CustomerID limit 10";l           运算符Esql支持的运算符有:加+、减-、乘*、除/、取模%、-负号。Esql语句如下:select 100/2 as OP from NorthwindEntities.Customers as c order by c.CustomerID limit 10l           比较运算符Esql支持的比较运算符有:=,>,>=,IS [NOT] NULL,<,[NOT] BETWEEN,!=,<>,[NOT] LIKE。Esql语句如下:select value p from NorthwindEntities.Products as p where p.UnitPrice > 20 order by p.ProductID limit 10l           逻辑运算符Esql支持的逻辑运算符有:and(&&),not(!),or(||)。Esql语句如下:select value p from NorthwindEntities.Products as p where p.UnitPrice > 20 and p.UnitPrice<100 order by p.ProductID limit 10或select value p from NorthwindEntities.Products as p where p.UnitPrice > 20 && p.UnitPrice<100 order by p.ProductID limit 10l           字符串连接运算符。加号 (+) 是 Entity SQL 中可将字符串串联起来的唯一运算符。Esql语句如下:select c.CustomerID + c.ContactName from NorthwindEntities.Customers as c order by c.CustomerID limit 10l           嵌套查询在 Entity SQL 中,嵌套查询必须括在括号中,将不保留嵌套查询的顺序select c1.CustomerID from( select value c from NorthwindEntities.Customers as c order by c.CustomerID limit 10) as c1l           日期时间函数Esql提供的日期时间函数有:CurrentDateTime()获取当前服务器的日期时间,还有month,day,year,second, Minute ,Hour等。例如:select CurrentDateTime() from NorthwindEntities.Customers as c order by c.CustomerID limit 10l           字符串函数Esql提供的字符串函数有:Concat,IndexOf,Left,Length,Ltrim,Replace,Reverse,Rtrim,SubString,Trim,ToLower,ToUpper.例如:select Reverse(p.ProductName) as ProductName from NorthwindEntities.Products as p order by p.ProductID limit 10l           GUIDEsql提供newguid()函数,产生一个新的Guid。例如:select newguid() from NorthwindEntities.Customers as c order by c.CustomerID limit 10l           数学函数:Abs,Ceiling,Floor,Roundl           统计函数:Avg,BigCount,Count,Max,Min,StDev,Suml           位计算函数如果提供 Null 输入,则这些函数返回 Null。这些函数的返回类型与参数类型相同。如果函数采用多个参数,则这些参数必须具有相同的类型。若要对不同类型执行位运算,则需要显式强制转换为相同类型.BitWiseAnd,BitWiseNot,BitWiseOr,BitWiseXorl           命名空间Entity SQL 引入命名空间以避免全局标识符(如类型名称、实体集、函数等)出现名称冲突。Entity SQL 中的命名空间支持与 .NET Framework 中的命名空间支持类似。Entity SQL 提供两种形式的 USING 子句:限定命名空间(其中,提供较短的别名以表示命名空间)和非限定命名空间,如下例所示:USING System.Data; USING tsql = System.Data; 例如:string esql = "using System; select cast(p.UnitPrice as Int32) from NorthwindEntities.Products as p order by p.ProductID limit 10 ";string esql = "using System;using SqlServer; select (cast(p.UnitPrice as Int32)),SqlServer.ltrim(p.ProductName) as nameLen from NorthwindEntities.Products as p order by p.ProductID limit 10 ";你用CurrentDateTime()获取当前服务器的日期时间,看看格式是什么样子的。