-
不允许从数据类型 datetime 到 int 的隐式转换。请使用 CONVERT 函数来运行此查询。3
直接在数据库中执行存储过程没错误,但是,运行代码的时候,在cs.executeQuery();时候报异常。
部分相关代码:
public List<PolicyVO> getPolicy(PolicyQueryVO paramVO, int start, int size) throws GenericException { /* 返回结果 */ List<PolicyVO> resultList = null; ResultSet rs = null; CallableStatement cs = null; Connection _con = null; String sql = null; try { /* * paramVO 不能为 null */ if (paramVO == null) { throw new Exception(" The param PolicyQueryVO is null."); } _con = getConnection(); resultList = new ArrayList<PolicyVO>(); try { sql = "{call sp_get_policy(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}"; cs = createCallableStatement(_con, sql); if (paramVO.getApldateMin() != null) { java.sql.Timestamp time_from_date = java.sql.Timestamp.valueOf(df2.format(paramVO.getApldateMin())); cs.setTimestamp(3, time_from_date); } else { cs.setNull(3, Types.TIMESTAMP); } if (paramVO.getApldateMax() != null) { java.sql.Timestamp time_to_date = java.sql.Timestamp.valueOf(df2.format(paramVO.getApldateMax())); cs.setTimestamp(4, time_to_date); } else { cs.setNull(4, Types.TIMESTAMP); } if (paramVO.getBirthday() != null) { java.sql.Timestamp birthday = java.sql.Timestamp.valueOf(df2.format(paramVO.getBirthday())); cs.setTimestamp(7, birthday); } else { cs.setNull(7, Types.TIMESTAMP); } if (paramVO.getEffectiveMinDate() != null) { java.sql.Timestamp time_from_date2 = java.sql.Timestamp.valueOf(df2.format(paramVO.getEffectiveMinDate())); cs.setTimestamp(14, time_from_date2); } else { cs.setNull(14, Types.TIMESTAMP); } if (paramVO.getEffectiveMaxDate() != null) { java.sql.Timestamp time_to_date2 = java.sql.Timestamp.valueOf(df2.format(paramVO.getEffectiveMaxDate())); cs.setTimestamp(15, time_to_date2); } else { cs.setNull(15, Types.TIMESTAMP); } rs = cs.executeQuery(); while (rs.next()) { PolicyVO tmpPolicyVO = new PolicyVOImpl(); T1aplVO tmpT1aplVO = new T1aplVOImpl(); T1plcbaseVO tmpT1plcbaseVO = new T1plcbaseVOImpl(); T1prdVOEx tmpT1prdVO = new T1prdVOExImpl(); T1isdVO tmpT1isdVO = new T1isdVOImpl(); TprdVO tmpTprdVO = new TPrdVOImpl(); ...... tmpT1plcbaseVO.setRecvtodate(rs.getDate("baserecvtodate")); tmpT1plcbaseVO.setPrttime(rs.getDate("baseprttime")); tmpT1plcbaseVO.setArrivedate(rs.getDate("basearrivedate")); tmpT1plcbaseVO.setApldate(rs.getDate("baseapldate")); tmpT1plcbaseVO.setLapsedate(rs.getDate("baselapsedate")); tmpT1prdVO.setIssuedate(rs.getDate("prdissuedate")); tmpT1prdVO.setInsexprtdate(rs.getDate("prdinsexprtdate")); tmpT1prdVO.setRecvexprtdate(rs.getDate("prdrecvexprtdate")); tmpT1aplVO.setBirthday(rs.getDate("aplbirthday")); tmpT1isdVO.setBirthday(rs.getDate("isdbirthday")); ..... resultList.add(tmpPolicyVO); } } catch (SQLException sqlEx) { sqlEx.printStackTrace(); throw ExceptionUtil.handleException(sqlEx, this.getClass().getName()); } finally { if (cs != null) { closeStatement(cs); } if (rs != null) { closeResultSet(rs); } if (!_con.isClosed()) { closeConnection(_con); } } } catch (Exception ex) { throw ExceptionUtil.handleException(ex, this.getClass().getName()); } finally { } return resultList; }
存储过程:
set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER PROCEDURE [dbo].[sp_get_policy] -- Add the parameters for the stored procedure here @plcno nvarchar(22) = NULL, @name nvarchar(60) = NULL, @apldateMin datetime = NULL, @apldateMax datetime = NULL, @custno nvarchar(19) = NULL, @certno nvarchar(30) = NULL, @birthday datetime = NULL, @mobile nvarchar(30) = NULL, @status nvarchar(135) = NULL, @t00salesno nvarchar(50) = NULL, @product nvarchar(50) = NULL, @downline nvarchar(5) = NULL, @allline nvarchar(5) = NULL, @start int = 1, @pageSize int = 0, @effectivedateMin datetime = NULL, @effectivedateMax datetime = NULL AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. DECLARE @sqlQuery nvarchar(4000) DECLARE @sqlCount nvarchar(4000) DECLARE @from nvarchar(1000) DECLARE @where nvarchar(1000) SET @plcno = rtrim(@plcno) SET @name = rtrim(@name) SET @custno = rtrim(@custno) SET @certno = rtrim(@certno) SET @mobile = rtrim(@mobile) SET @status = rtrim(@status) SET @t00salesno = rtrim(@t00salesno) SET @product = rtrim(@product) DECLARE @end int SET NOCOUNT ON; SET @sqlQuery = '' SET @from = '' SET @where = '' -- Insert statements for procedure here SET @sqlQuery = @sqlQuery + N' t1plcbase.recvconvacct ppsnumber,t1plcbase.comagentno1 comagentno1, t1plcbase.comagentno2 comagentno2,t1plcbase.plcno baseplcno,t1plcbase.paperno basepaperno,t1plcbase.efftdate baseefftdate' SET @sqlQuery = @sqlQuery + ', t1plcbase.status basestatus,t1plcbase.recvway baserecvway,t1plcbase.recvtodate baserecvtodate' SET @sqlQuery = @sqlQuery + ', t1plcbase.prttime baseprttime, t1plcbase.arrivedate basearrivedate' SET @sqlQuery = @sqlQuery + ', t1plcbase.apldate baseapldate, t1plcbase.agentno baseagentno, t1plcbase.agentno2 baseagentno2' SET @sqlQuery = @sqlQuery + ', t1plcbase.isapl baseisapl, t1plcbase.currency basecurrency, t1plcbase.primprdcode baseprimprdcode' --SET @sqlQuery = @sqlQuery + ', T1recvacct.bank acctbank,T1recvacct.acctname acctacctname,T1recvacct.acct acctacct' SET @sqlQuery = @sqlQuery + ', T1prd.prdcode prdprdcode, T1prd.issuedate prdissuedate, T1prd.insamt prdinsamt, T1prd.stdprm prdstdprm, T1prd.recvmode prdrecvmode' SET @sqlQuery = @sqlQuery + ', T1prd.insexprtdate prdinsexprtdate, T1prd.recvterm prdrecvterm, T1prd.recvexprtdate as prdrecvexprtdate' SET @sqlQuery = @sqlQuery + ', T1prd.realprm prdrealprm, T1prd.prdserno prdprdserno' SET @sqlQuery = @sqlQuery + ', t_prd.name tprdname' SET @sqlQuery = @sqlQuery + ', T1apl.name aplname, T1apl.custno aplcustno, T1apl.sex aplsex, T1apl.certtype aplcerttype' SET @sqlQuery = @sqlQuery + ', T1apl.nationality aplnationality, T1apl.address apladdress, T1apl.address2 apladdress2' SET @sqlQuery = @sqlQuery + ', T1apl.address3 apladdress3, T1apl.mobile aplmobile, T1apl.housephone aplhousephone' SET @sqlQuery = @sqlQuery + ', T1apl.houseaddress aplhouseaddress, T1apl.houseaddress2 aplhouseaddress2, T1apl.houseaddress3 aplhouseaddress3' SET @sqlQuery = @sqlQuery + ', T1apl.edrno apledrno, T1apl.birthday aplbirthday, T1apl.certno aplcertno, T1apl.phoneno aplphoneno' SET @sqlQuery = @sqlQuery + ', T1apl.email aplemail' SET @sqlQuery = @sqlQuery + ', T1isd.name isdname, T1isd.custno isdcustno, T1isd.status isdstatus, T1isd.plcno isdplcno, T1isd.sex isdsex' SET @sqlQuery = @sqlQuery + ', T1isd.certtype isdcerttype, T1isd.nationality isdnationality, T1isd.contaddress isdcontaddress' SET @sqlQuery = @sqlQuery + ', T1isd.contaddress2 isdcontaddress2, T1isd.contaddress3 isdcontaddress3, T1isd.mobile isdmobile' SET @sqlQuery = @sqlQuery + ', T1isd.housephoneno isdhousephoneno, T1isd.houseaddress isdhouseaddress, T1isd.houseaddress2 isdhouseaddress2' SET @sqlQuery = @sqlQuery + ', T1isd.houseaddress3 isdhouseaddress3, T1isd.edrno isdedrno, T1isd.birthday isdbirthday, T1isd.certno isdcertno' SET @sqlQuery = @sqlQuery + ', T1isd.contphoneno isdcontphoneno, T1isd.email isdemail' SET @sqlQuery = @sqlQuery + ', t01_sales.t01name agentname, (select t01_sales.t01name from incramis..t01_sales where t01_sales.t00salesno = t1plcbase.agentno2) agentname2' SET @from = @from + N' FROM incrLifeproNew.dbo.t1plcbase left join incrLifeproNew.dbo.T1prd' SET @from = @from + ' on t1plcbase.plcno = T1prd.plcno AND t1plcbase.primprdcode = t1prd.prdcode' SET @from = @from + ' left join incrLifeproNew.dbo.t1apl on t1plcbase.plcno = T1apl.plcno' SET @from = @from + ' left join incrLifeproNew.dbo.T1isd on t1plcbase.plcno = T1isd.plcno' SET @from = @from + ' left join incrLifeproNew.dbo.t_prd on T1prd.prdcode = t_prd.prdcode' SET @from = @from + ' left join incramis.dbo.t01_sales on t1plcbase.agentno = t01_sales.t00salesno' -- Add by Terry Hung 20100715 SET @where = @where + ' WHERE t1prd.prdcode = t1prd.primprdcode and t1prd.prdserno = 1 and (t1prd.enddate is null or year(t1prd.enddate)= 1899) and t1prd.status <> ''4''' SET @where = @where + ' AND (t1apl.enddate is null or year(t1apl.enddate)= 1899) and t1apl.status = ''2''' --SET @where = @where + ' AND t1isd.enddate is null and (t1isd.edrno is null or t1isd.edrno = ''00'')' SET @where = @where + ' AND (t1isd.enddate is null or year(t1isd.enddate)= 1899) ' IF (@product IS NOT NULL) SET @where = @where + ' AND t_prd.name like ''%' + @product + '%''' IF (@name IS NOT NULL) SET @where = @where + ' AND t1apl.name like ''%' + @name + '%''' IF (@plcno IS NOT NULL) SET @where = @where + ' AND t1plcbase.plcno like ''%' + @plcno + '%''' IF (@apldateMin IS NOT NULL) SET @where = @where + ' AND (DATEDIFF(DAY, t1plcbase.apldate, ''' + CONVERT(nvarchar(50), @apldatemin, 101) + ''') <= 0)' IF (@apldateMax IS NOT NULL) SET @where = @where + ' AND (DATEDIFF(DAY, t1plcbase.apldate, ''' + CONVERT(nvarchar(50), @apldatemax, 101) + ''') >= 0)' IF (@effectivedateMin IS NOT NULL) SET @where = @where + ' AND (DATEDIFF(DAY, t1plcbase.prttime, ''' + CONVERT(nvarchar(50), @effectivedateMin, 101) + ''') <= 0)' IF (@effectivedateMax IS NOT NULL) SET @where = @where + ' AND (DATEDIFF(DAY, t1plcbase.prttime, ''' + CONVERT(nvarchar(50), @effectivedateMax, 101) + ''') >= 0)' IF (@custno IS NOT NULL) SET @where = @where + ' AND t1apl.custno like ''%' + @custno + '%''' IF (@certno IS NOT NULL) SET @where = @where + ' AND t1apl.certno like ''%' + @certno + '%''' IF (@birthday IS NOT NULL) SET @where = @where + ' AND t1apl.birthday = ''' + CAST(@birthday AS nvarchar(50)) + '''' IF (@mobile IS NOT NULL) SET @where = @where + ' AND t1apl.mobile like ''%' + @mobile + '%''' IF (@status IS NOT NULL) SET @where = @where + ' AND t1plcbase.status in (''' + @status + ''')' IF (@t00salesno IS NOT NULL) BEGIN IF (@downline IS NOT NULL AND @allline IS NOT NULL) BEGIN SET @where = @where + ' AND (t1plcbase.agentno = ''' + @t00salesno + ''' OR t1plcbase.agentno2 = ''' + @t00salesno + ''' OR t1plcbase.comagentno1 = ''' + @t00salesno + ''' OR t1plcbase.comagentno2 = ''' + @t00salesno + '''' IF (@downline = 'false' AND @allline = 'false') BEGIN SET @where = @where + ')' END ELSE IF (@allline = 'true') BEGIN SET @where = @where + ' OR t1plcbase.agentno in (select t00salesno from incramis..t99_saleslevel where t01engage = ''' + @t00salesno +'''))' END ELSE BEGIN SET @where = @where + ' OR t01_sales.t01engage = ''' + @t00salesno + ''')' END END ELSE BEGIN SET @where = @where + ' AND (t1plcbase.agentno = ''' + @t00salesno + ''' OR t1plcbase.agentno2 = ''' + @t00salesno + ''' OR t1plcbase.comagentno1 = ''' + @t00salesno + ''' OR t1plcbase.comagentno2 = ''' + @t00salesno + ''') ' END END if @start<=0 Set @start = 1 SET @end = @start + @pageSize - 1 SET @sqlQuery = N'Select * FROM (select ROW_NUMBER() Over(order by t1plcbase.plcno) as rowId,' + @sqlQuery + @from + @Where SET @sqlQuery = @sqlQuery + ') as t where rowId between ' + Convert(varchar(50),@start) + ' and ' + Convert(varchar(50),@end) EXEC(@sqlQuery) END
DECLARE @return_value int --直接在数据库中这样执行是没有报错的。 EXEC @return_value = [dbo].[sp_get_policy] @apldateMax = N'2011-4-20', @birthday = N'2011-4-20', @effectivedateMin = N'2011-4-20', @effectivedateMax = N'2011-4-20' SELECT 'Return Value' = @return_value GO
2011年4月20日 10:34
目前还没有答案
相关推荐
1、将Int 转为varchar经常用 concat函数,比如concat(8,’0′) 得到字符串 ’80’ 2、将varchar 转为Int 用 cast(a as signed) a为varchar类型的字符串 总结:类型转换和SQL Server一样,就是类型参数有点点不同 : ...
--begin 内联表值函数不能用begin-end return select name from test --end --调用 select * from return_test() --运行结果 --name --test1 --test2 --test3 --test4 3、多语句表值函数 create ...
在上篇文章给大家讲了MySQL数据库中把int转化varchar引发的慢查询,本文给大家介绍Mysql数据库中把varchar类型转化为int类型的方法,一起看看吧! mysql为我们提供了两个类型转换函数:CAST和CONVERT,现成的东西...
insertToSql函数是将dt中的各项值导入SQL,注意的是EXCEL字段要与SQL字段一样,且声明变量时的数据类型要一致 使用方法:在click事件下 DataRow dr = null; for (int i = 0; i ; i++){ dr = dt.Rows[i]; ...
常用 Convert 方法有: 第2页 C#(WINFORM)学习 C# Convert.ToBoolean Convert.ToByte Convert.ToChar Convert.ToDateTime Convert.ToDecimal Convert.ToDouble Convert.ToInt16 Convert.ToInt32 Convert.ToInt64 ...
将一种数据类型的表达式显式转换为另一种数据类型的表达式。CAST 和 CONVERT 提供相似的功能。 DECLARE @myval decimal (5, 2) SET @myval = 193.57 SELECT CAST(CAST(@myval AS varbinary(20)) AS decimal(10,5)) ...
Console.WriteLine("请输入数字:"); int x; //输入的数字 x = Convert.ToInt32(Console.ReadLine()); DateTime da = DateTime.Now; 。。。。。
转换为数字:Convert.ToInt64(),Convert.ToInt32(),Convert.ToInt16() 是按照数字位数由长到短 转换为日期:Convert.ToDateTime() ________________________________________ dim objConnection as ...
因为这样可以避免 top的字段如果是逻辑索引的,查询的结果后实际表中的不一致(逻辑索引中的数据有可能和数据表中的不一致,而查询时如果处在索引则首先查询索引) 14、说明:前10条记录 select top 10 * form table...
--对销售表ProOut的SaleDate 列进行约束,当不输入值时,系统默认其值为系统当前日期 CREATE DEFAULT Today AS GETDATEA() GO /*ALTER TABLE ProOut ADD CONSTRAINT DF_ProOut_SaleDate DEFAULT('当前日期')FOR ...
因为这样可以避免 top的字段如果是逻辑索引的,查询的结果后实际表中的不一致(逻辑索引中的数据有可能和数据表中的不一致,而查询时如果处在索引则首先查询索引) 14、说明:前10条记录 select top 10 * form table...
因为这样可以避免 top的字段如果是逻辑索引的,查询的结果后实际表中的不一致(逻辑索引中的数据有可能和数据表中的不一致,而查询时如果处在索引则首先查询索引) 14、说明:前10条记录 select top 10 * form ...
1.1.6 Convert类——类型转换 8 1.1.7 常量——值不改变的量 9 1.1.8 Dispose方法——释放资源 10 1.1.9 迭代器——相同类型的值的有序序列的一段代码 10 1.1.10 泛型——处理算法和数据结构 11 1.1.11 分部类——将...
Fn.Convert(SqlType.Int,"123").As("转换类型")). From(a).Where(a.UserId == 2) ); //下面是插入语句,这里是指明需要插入的列来插入 Sql.ExecuteNonQuery((a) => Sub.Insert(a).Fields(a.UserName, a.RoleId, a...
id='(Container.DataItem, "数据字段1")%>' & name='(Container.DataItem, "数据字段2")%>' /> 7.表格点击改变颜色 if (e.Item.ItemType == ListItemType.Item ||e.Item.ItemType == ListItemType.AlternatingItem...
//保存从入住单中选择得到的客人入住单号 private System.ComponentModel.IContainer components = null; public ClientConsume() { // 该调用是 Windows 窗体设计器所必需的。 InitializeComponent();...