SQLserver: delete语句没有From,为什么可以执行

DELETE [dbo].[T_VrcgGrpMaster] WHERE TenantID = '1234' AND WordGroup = 'bbbb' ;

DELETE FROM [dbo].[T_VrcgGrpMaster] WHERE TenantID = '1234' AND WordGroup = 'bbbb' ;
都可以删除一条数据,第一个没有FROM关键字为什么可以执行

1个回答

showbo
支付宝加好友偷能量挖 回复chen510103032: 记得采纳了:)...
接近 3 年之前 回复
chen510103032
chen510103032 ok,学习了
接近 3 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
com.microsoft.sqlserver.jdbc.SQLServerException: 'upwd' 附近有语法错误。

这个是咋回事啊?求大神解下惑 jba.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String uuser=jta.getText(); String upwd=pwd.getText(); userdao udao=new userdao(); ** int n=udao.getmarker(uuser, upwd);**//提示我这行错误 if(n!=-1) { if(n==0) { JOptionPane.showMessageDialog(null, "欢迎管理大大!!!!!!"); }else { JOptionPane.showMessageDialog(null, "您好,欢迎您,尊敬的用户"); } Login.this.dispose(); new test(); }else { JOptionPane.showMessageDialog(null, "账号或密码错误"); } } }); con=DBHelper.getcon(); String sql="select * from tb_user where uuser="+uuser+"and upwd="+upwd; ps=con.prepareStatement(sql); rs=ps.executeQuery();//还有这里也提示我错误

SQL delete in 配合使用 为什么无法删除

SQL delete in 配合使用 为什么无法删除 select * from ccc where SSQ_CHA in(select SSQ_CHA from ssqcha where SSQ_SUM>27) 能查询 select SSQ_CHA from ssqcha where SSQ_SUM>27 就 1条数据 delete from ccc where SSQ_CHA in(select SSQ_CHA from ssqcha where SSQ_SUM>27) 无法删 为什么 半天没有反应?

Druid连接SqlServer报错,为啥都连接了sqlserver还执行SHOW TABLES?

SpringBoot + Guns脚手架改成使用sqlserver,在最后时刻报错了,原因是sqlserver执行了mysql的语句SHOW TABLES,druid内部会执行这一句吗?mysql转sqlserver该如何实现? ``` 2019-12-09 15:04:10.196 INFO 3788 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/mgr/add]}" onto public cn.stylefeng.roses.core.reqres.response.ResponseData com.jsnjfz.manage.modular.system.controller.UserMgrController.add(com.jsnjfz.manage.modular.system.transfer.UserDto,org.springframework.validation.BindingResult) 2019-12-09 15:04:10.196 INFO 3788 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/mgr/delete]}" onto public cn.stylefeng.roses.core.reqres.response.ResponseData com.jsnjfz.manage.modular.system.controller.UserMgrController.delete(java.lang.Integer) 2019-12-09 15:04:10.196 INFO 3788 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/mgr/list]}" onto public java.lang.Object com.jsnjfz.manage.modular.system.controller.UserMgrController.list(java.lang.String,java.lang.String,java.lang.String,java.lang.Integer) 2019-12-09 15:04:10.196 INFO 3788 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/mgr/reset]}" onto public cn.stylefeng.roses.core.reqres.response.ResponseData com.jsnjfz.manage.modular.system.controller.UserMgrController.reset(java.lang.Integer) 2019-12-09 15:04:10.196 INFO 3788 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/mgr/user_info]}" onto public java.lang.String com.jsnjfz.manage.modular.system.controller.UserMgrController.userInfo(org.springframework.ui.Model) 2019-12-09 15:04:10.196 INFO 3788 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/mgr/freeze]}" onto public cn.stylefeng.roses.core.reqres.response.ResponseData com.jsnjfz.manage.modular.system.controller.UserMgrController.freeze(java.lang.Integer) 2019-12-09 15:04:10.196 INFO 3788 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/mgr/view/{userId}]}" onto public com.jsnjfz.manage.modular.system.model.User com.jsnjfz.manage.modular.system.controller.UserMgrController.view(java.lang.Integer) 2019-12-09 15:04:10.196 INFO 3788 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/mgr/setRole]}" onto public cn.stylefeng.roses.core.reqres.response.ResponseData com.jsnjfz.manage.modular.system.controller.UserMgrController.setRole(java.lang.Integer,java.lang.String) 2019-12-09 15:04:10.196 INFO 3788 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/mgr/user_chpwd]}" onto public java.lang.String com.jsnjfz.manage.modular.system.controller.UserMgrController.chPwd() 2019-12-09 15:04:10.196 INFO 3788 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/mgr/changePwd]}" onto public java.lang.Object com.jsnjfz.manage.modular.system.controller.UserMgrController.changePwd(java.lang.String,java.lang.String,java.lang.String) 2019-12-09 15:04:10.196 INFO 3788 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/mgr/edit]}" onto public cn.stylefeng.roses.core.reqres.response.ResponseData com.jsnjfz.manage.modular.system.controller.UserMgrController.edit(com.jsnjfz.manage.modular.system.transfer.UserDto,org.springframework.validation.BindingResult) throws javax.naming.NoPermissionException 2019-12-09 15:04:10.212 INFO 3788 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/mgr/role_assign/{userId}]}" onto public java.lang.String com.jsnjfz.manage.modular.system.controller.UserMgrController.roleAssign(java.lang.Integer,org.springframework.ui.Model) 2019-12-09 15:04:10.212 INFO 3788 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/mgr/user_add]}" onto public java.lang.String com.jsnjfz.manage.modular.system.controller.UserMgrController.addView() 2019-12-09 15:04:10.212 INFO 3788 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/mgr/user_edit/{userId}]}" onto public java.lang.String com.jsnjfz.manage.modular.system.controller.UserMgrController.userEdit(java.lang.Integer,org.springframework.ui.Model) 2019-12-09 15:04:10.212 INFO 3788 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/mgr/upload],methods=[POST]}" onto public java.lang.String com.jsnjfz.manage.modular.system.controller.UserMgrController.upload(org.springframework.web.multipart.MultipartFile) 2019-12-09 15:04:10.212 INFO 3788 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/mgr/unfreeze]}" onto public cn.stylefeng.roses.core.reqres.response.ResponseData com.jsnjfz.manage.modular.system.controller.UserMgrController.unfreeze(java.lang.Integer) 2019-12-09 15:04:10.212 INFO 3788 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest) 2019-12-09 15:04:10.212 INFO 3788 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) 2019-12-09 15:04:10.212 INFO 3788 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/code/generate],methods=[POST]}" onto public java.lang.Object cn.stylefeng.guns.generator.modular.controller.CodeController.generate(cn.stylefeng.guns.generator.executor.model.GenQo) 2019-12-09 15:04:10.212 INFO 3788 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/code]}" onto public java.lang.String cn.stylefeng.guns.generator.modular.controller.CodeController.blackboard(org.springframework.ui.Model) 2019-12-09 15:04:10.353 INFO 3788 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2019-12-09 15:04:10.353 INFO 3788 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/static/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2019-12-09 15:04:10.353 INFO 3788 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/swagger-ui.html] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2019-12-09 15:04:10.415 INFO 3788 --- [ restartedMain] .m.m.a.ExceptionHandlerExceptionResolver : Detected @ExceptionHandler methods in globalExceptionHandler 2019-12-09 15:04:10.415 INFO 3788 --- [ restartedMain] .m.m.a.ExceptionHandlerExceptionResolver : Detected @ExceptionHandler methods in defaultControllerExceptionHandler 2019-12-09 15:04:11.071 INFO 3788 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729 2019-12-09 15:04:11.114 INFO 3788 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup 2019-12-09 15:04:11.161 INFO 3788 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8001 (http) with context path '' 2019-12-09 15:04:11.161 INFO 3788 --- [ restartedMain] c.jsnjfz.manage.WebstackGunsApplication : Started WebstackGunsApplication in 71.82 seconds (JVM running for 72.932) JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@7a595887] will not be managed by Spring 2019-12-09 15:08:40.389 ERROR 3788 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed com.baomidou.mybatisplus.exceptions.MybatisPlusException: java.lang.reflect.InvocationTargetException at com.baomidou.mybatisplus.MybatisSqlSessionTemplate$SqlSessionInterceptor.invoke(MybatisSqlSessionTemplate.java:405) at com.sun.proxy.$Proxy86.selectList(Unknown Source) at com.baomidou.mybatisplus.MybatisSqlSessionTemplate.selectList(MybatisSqlSessionTemplate.java:195) at com.baomidou.mybatisplus.mapper.SqlRunner.selectObjs(SqlRunner.java:140) at cn.stylefeng.roses.core.db.DbInitializer.initTable(DbInitializer.java:97) at cn.stylefeng.roses.core.db.DbInitializer.dbInit(DbInitializer.java:71) at cn.stylefeng.roses.core.db.listener.InitTableListener.onApplicationEvent(InitTableListener.java:42) at cn.stylefeng.roses.core.db.listener.InitTableListener.onApplicationEvent(InitTableListener.java:32) at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:400) at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:354) at org.springframework.boot.context.event.EventPublishingRunListener.running(EventPublishingRunListener.java:103) at org.springframework.boot.SpringApplicationRunListeners.running(SpringApplicationRunListeners.java:78) at org.springframework.boot.SpringApplication.run(SpringApplication.java:343) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) at com.jsnjfz.manage.WebstackGunsApplication.main(WebstackGunsApplication.java:36) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) Caused by: java.lang.reflect.InvocationTargetException: null at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.baomidou.mybatisplus.MybatisSqlSessionTemplate$SqlSessionInterceptor.invoke(MybatisSqlSessionTemplate.java:401) ... 23 common frames omitted Caused by: org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: java.sql.SQLException: sql injection violation, syntax error: syntax error, error in :'SHOW TABLES', expect IDENTIFIER, actual IDENTIFIER pos 4, line 1, column 1, token IDENTIFIER SHOW : SHOW TABLES ### The error may involve com.baomidou.mybatisplus.mapper.SqlRunner.SelectObjs ### The error occurred while executing a query ### SQL: SHOW TABLES ### Cause: java.sql.SQLException: sql injection violation, syntax error: syntax error, error in :'SHOW TABLES', expect IDENTIFIER, actual IDENTIFIER pos 4, line 1, column 1, token IDENTIFIER SHOW : SHOW TABLES at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141) ... 28 common frames omitted Caused by: java.sql.SQLException: sql injection violation, syntax error: syntax error, error in :'SHOW TABLES', expect IDENTIFIER, actual IDENTIFIER pos 4, line 1, column 1, token IDENTIFIER SHOW : SHOW TABLES at com.alibaba.druid.wall.WallFilter.checkInternal(WallFilter.java:798) at com.alibaba.druid.wall.WallFilter.connection_prepareStatement(WallFilter.java:251) at com.alibaba.druid.filter.FilterChainImpl.connection_prepareStatement(FilterChainImpl.java:568) at com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl.prepareStatement(ConnectionProxyImpl.java:342) at com.alibaba.druid.pool.DruidPooledConnection.prepareStatement(DruidPooledConnection.java:349) at org.apache.ibatis.executor.statement.PreparedStatementHandler.instantiateStatement(PreparedStatementHandler.java:87) at org.apache.ibatis.executor.statement.BaseStatementHandler.prepare(BaseStatementHandler.java:88) at org.apache.ibatis.executor.statement.RoutingStatementHandler.prepare(RoutingStatementHandler.java:59) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:49) at com.baomidou.mybatisplus.plugins.PaginationInterceptor.intercept(PaginationInterceptor.java:112) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61) at com.sun.proxy.$Proxy114.prepare(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:49) at cn.stylefeng.roses.core.datascope.DataScopeInterceptor.intercept(DataScopeInterceptor.java:46) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61) at com.sun.proxy.$Proxy114.prepare(Unknown Source) at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:85) at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62) at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:326) at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:63) at com.sun.proxy.$Proxy113.query(Unknown Source) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148) ... 29 common frames omitted Caused by: com.alibaba.druid.sql.parser.ParserException: syntax error, error in :'SHOW TABLES', expect IDENTIFIER, actual IDENTIFIER pos 4, line 1, column 1, token IDENTIFIER SHOW at com.alibaba.druid.sql.parser.SQLParser.printError(SQLParser.java:284) at com.alibaba.druid.sql.parser.SQLStatementParser.parseStatementList(SQLStatementParser.java:426) at com.alibaba.druid.sql.parser.SQLStatementParser.parseStatementList(SQLStatementParser.java:83) at com.alibaba.druid.wall.WallProvider.checkInternal(WallProvider.java:624) at com.alibaba.druid.wall.WallProvider.check(WallProvider.java:578) at com.alibaba.druid.wall.WallFilter.checkInternal(WallFilter.java:785) ... 65 common frames omitted 2019-12-09 15:08:40.394 INFO 3788 --- [ restartedMain] ConfigServletWebServerApplicationContext : Closing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@e8fcbe7: startup date [Mon Dec 09 15:02:59 CST 2019]; root of context hierarchy 2019-12-09 15:08:40.395 INFO 3788 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown 2019-12-09 15:08:40.395 INFO 3788 --- [ restartedMain] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} closed 2019-12-09 15:08:40.395 INFO 3788 --- [ restartedMain] o.s.c.ehcache.EhCacheManagerFactoryBean : Shutting down EhCache CacheManager ```

navicat执行delete 报错

数据库版本信息 ![图片说明](https://img-ask.csdn.net/upload/201708/15/1502765759_595041.png) 执行的sql,及报错信息 ![图片说明](https://img-ask.csdn.net/upload/201708/15/1502765848_668990.png) ![图片说明](https://img-ask.csdn.net/upload/201708/15/1502765871_832362.png)

SQL触发器DELETE的使用方法

我的情况是这样的 有A,B两张表,B中fcode,fqty,fitemid,fbillno的内容(筛选条件为fbillno的值为CPRK)是引用自A表的,现在我想做一个触发器,当A表中出现两个相同的fcode时(出现相同fcode时,fbillno必不相同,值为CPRK或XSCK),把B表中那条重复fcode的得行删除... 新手求解.... 举例: A表 rowid fcode fqty fitemid fbillno 1 10102 20 10 CPRK01 2 10103 10 13 CPRK02 3 10102 20 10 XSCK01 B表 rowid fcode fqty fitemid fbillno 1 10102 20 10 CPRK01 2 10103 10 13 CPRK02 现在想用触发器实现的功效就是当出现A表第三行这种情况时,B表第一行能自动删除

SQL server 数据库 关于 insert into …… select 的问题

这个存储过程每分钟执行一次单线程(A表中除了插入还有修改[count] = 3 的都是多线程。) 功能:就是将A 表[count] > 2 的数据备份到B表,并将A表中已备份的数据删除掉, 但是有时候A表的一条数据会在B表中备份多条(那个数据在A表中确实就一条),还有我看B表中插入时间都是相隔几毫 秒说明都是一次插入的, 我不明白为什么会出现这种情况 select distinct [id] into #A_temp from A where [count] > 2; //判断是否有数据 if exists(select [id] from #A_temp) begin /**将已发送的记录导入到备份表中**/ insert into B( col1, col2 ) select col1,col2 from A with(nolock) where [id] in (select [id] from #A_temp); /**将已发送的记录导入到备份表中**/ --删除已备份的记录 delete from A where [id] in (select [id] from #A_temp); end

jdbc无法执行删除操作

import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.Scanner; public class delt { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub //装载驱动 Connection con=null; PreparedStatement pre=null; Scanner input=new Scanner(System.in); System.out.print("输入要删除的姓名:"); String name=input.next(); try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); //得到数据库的连接对象 String url="jdbc:sqlserver://127.0.0.1:1433;DatabaseName=us"; con=DriverManager.getConnection(url,"sa","123456"); //编写SQL语句 String sql="delete name from st where name=?"; //建立一个预处理对象 pre=con.prepareStatement(sql); pre.setString(1,name); System.out.println("11"); int i=pre.executeUpdate(); //con.commit(); System.out.println("22"); if(i>0) System.out.println("删除成功"); else System.out.println("操作未成功"); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ try { con.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } ``` ``` 输入要删除的姓名:王二 11 com.microsoft.sqlserver.jdbc.SQLServerException: 对象名 'name' 无效。 at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(Unknown Source) at com.microsoft.sqlserver.jdbc.IOBuffer.processPackets(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.getPrepExecResponse(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PreparedStatementExecutionRequest.executeStatement(Unknown Source) at com.microsoft.sqlserver.jdbc.CancelableRequest.execute(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeRequest(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeUpdate(Unknown Source) at delt.main(delt.java:33)

SQL存储过程比SQL语句慢,甚至卡死

因公司业务需要,需要每天凌晨从别的系统(Oracle数据库)取前一天的数据,建了存储过程后,发现执行存储过程经常卡死,单独执行却挺快,不知道是哪里出了问题,求大神帮忙分析下,万分感谢!以下为存储过程代码: USE [HERP_BHYY] GO /****** 对象: StoredProcedure [dbo].[sp_GetHISChargeOReceiptDataInHISDBbyDay] 脚本日期: 12/03/2013 08:36:35 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[sp_GetHISChargeOReceiptDataInHISDBbyDay] @ImpDate as DATETIME AS BEGIN --SET NOCOUNT ON; DECLARE @ST_DATE AS DATETIME DECLARE @ED_DATE AS DATETIME DECLARE @TEMP_DATE DATETIME IF @ImpDate is not null begin SET @ST_DATE=LEFT(@ImpDate,10) SET @ED_DATE=dateadd(day,1,@ST_DATE) end delete hisdb2.dbo.his_charge_acc_o where charge_date>=@ST_DATE and charge_date<@ED_DATE insert into hisdb2.dbo.his_charge_acc_o (charge_date, deposit_pre, pay_type_code, patient_type_code, his_irecord, charge_money, patient_code, invoice_no, operator, acc_flag, balance_flag, invoice_type) select charge_date, deposit_pre, pay_type_code, patient_type_code, his_irecord, charge_money, patient_code, invoice_no, operator, acc_flag, balance_flag, invoice_type from openquery(HIS,'select charge_date, deposit_pre, pay_type_code, patient_type_code, his_irecord, charge_money, patient_code, invoice_no, operator, acc_flag, balance_flag, invoice_type from data_hrp.HIS_CHARGE_ACC_o') where charge_date>=@ST_DATE and charge_date<@ED_DATE end

SQL Server 删除指定范围内的记录,如第10条到第100条

SQL 删除指定范围内的记录,如第10条到第100条,如果是用where id>10 and id<100的那就算了,这种情况只适用于id是连续的,我想实现的是删除表中从第10条记录到第100条记录之间的数据,也就是说90条数据会被清除,而且清除的数据的id可能会大于100

SQL Server的update的多个表的更新

update Student set Adress='山东省济南市文化路1号院' where StudentNo='S1201302004' update Student set GradeId=2 where StudentNo='S1201302005' update Student set Adress='未知@' where Adress=null update Subject set ClassHour=55 where SubjectName='走进JAVA编程世界' ***update Result and Subject set StudentResult=StudentResult+5 where ExamDate='2013-10-18'and StudentResult <60 SubjectName='走进JAVA编程世界' update Result,Subject set StudentResult=55 where StudentNo='S1201302002' and ExamDate='2013-10-18'and SubjectName='HTML和CSS网页技术' 从***那里开始出错

Sql Server 触发器变量赋值不成功,求大神帮忙看看!!

![图片说明](https://img-ask.csdn.net/upload/201707/28/1501249642_360347.png) ![图片说明](https://img-ask.csdn.net/upload/201707/28/1501249665_430948.png) ![图片说明](https://img-ask.csdn.net/upload/201707/28/1501249676_604135.png) ![图片说明](https://img-ask.csdn.net/upload/201707/28/1501249688_879767.png) 触发器代码: CREATE TRIGGER [dbo].[job] ON [dbo].[Students] AFTER INSERT, UPDATE, DELETE AS BEGIN declare @c int, @b varchar; select @c = MajorID from inserted; select @b = Majors.Name from Majors inner join inserted On Majors.ID = inserted.MajorID; PRINT @b; PRINT @c; PRINT 'sdjkashdkasjhdka'; INSERT INTO tuchu(ID,NAME,Age,City,MajorID) VALUES(1,'张三',16,@b,11) END 原意是想通过Students这个表的触发器,触发时插入sql,在tuchu这个表的City字段,通过第三张表Majobs,插入变量@b(希望是'美学'这个字符串),之前成功过,不知道问题出在哪,怎么试都不行了..学习阶段..求大神开导!!!!

sql语句一直提示错误!

delete from PictureDB.dbo.picture where picture.num= (select max(num) from (select top 20 num from PictureDB.dbo.picture)); 找不出错误,求高人指点 老是说最后一个)左右有错误

sql server创建存储过程初始化失败,不知道为什么,求大侠帮忙看看

CREATE PROCEDURE p_getLogFilter @account VARCHAR(20), @split VARCHAR(10) AS BEGIN DECLARE @splitlen INT, @au_id CHAR(50), @s VARCHAR(MAX), @cform VARCHAR(255), @dbname VARCHAR(200), @sqlstr NVARCHAR(MAX) --获取数据库名 SELECT @dbname=dbname FROM accinfo WHERE accid=@account --创建临时表 IF EXISTS (SELECT * FROM tempdb.dbo.sysobjects WHERE id = object_id(N'tempdb..##templogdescp') AND type='U') DROP TABLE ##templogdescp CREATE TABLE ##templogdescp(operate VARCHAR(MAX),cform VARCHAR(255)) DELETE FROM ##templogdescp SET @sqlstr = 'select @au_id = min( cguid ) from ['+@dbname+'].[dbo].[CM_LOG] where ctype=1 and caction=''查询''' EXEC SP_EXECUTESQL @sqlstr,N'@au_id char(20) OUTPUT', @au_id OUTPUT --select @au_id = min( cguid ) from CM_LOG where ctype=1 and caction='查询' SET @splitlen=LEN(@split+'a')-2 WHILE @au_id IS NOT NULL BEGIN --set @s = (select substring(CDESCP,charindex('[',CDESCP)+1,len(CDESCP)-(case when charindex('[',CDESCP)!=0 then charindex('[',CDESCP)+1 else 0 end)) from [A399992014].[dbo].CM_LOG where cguid = @au_id) --set @cform = (select cform from [A399992014].[dbo].CM_LOG where cguid=@au_id) SET @sqlstr = 'select @s=substring(CDESCP,charindex(''['',CDESCP)+1,len(CDESCP)-(case when charindex(''['',CDESCP)!=0 then charindex(''['',CDESCP)+1 else 0 end)) from ['+@dbname+'].[dbo].CM_LOG where cguid = '''+@au_id+'''' EXEC SP_EXECUTESQL @sqlstr,N'@s varchar(max) OUTPUT', @s OUTPUT SET @sqlstr = 'select @cform=cform from ['+@dbname+'].[dbo].CM_LOG where cguid='''+@au_id+'''' EXEC SP_EXECUTESQL @sqlstr,N'@cform varchar(255) OUTPUT', @cform OUTPUT WHILE CHARINDEX(@split,@s)>0 BEGIN INSERT ##templogdescp VALUES(LEFT(@s,CHARINDEX(@split,@s)-1),@cform) SET @s=STUFF(@s,1,CHARINDEX(@split,@s)+@splitlen,'') END IF(@s IS NOT NULL) INSERT ##templogdescp VALUES(@s,@cform) --select @au_id = min( cguid ) from [A399992014].[dbo].CM_LOG where cguid > @au_id and ctype=1 and caction='查询' SET @sqlstr = 'select @au_id = min( cguid ) from ['+@dbname+'].[dbo].CM_LOG where cguid > '''+@au_id+''' and ctype=1 and caction=''查询''' EXEC SP_EXECUTESQL @sqlstr,N'@au_id varchar(255) OUTPUT', @au_id OUTPUT END RETURN END

Sql语句 删除数据记录

这个删除语句到底哪错了...... string str = "Delete from EmployeeInfo where 员工编号='"+textBox1 .Text +"'"; 放到 查询 里去检查,说是 '+' 附近有语法错误。

尝试写了一个 JDBC 操作 SQLServer 的工具类,但是好像有问题,求大神帮忙指正

java新人,尝试写了一个 JDBC 操作 SQLServer 的工具类,但是好像有问题,调用 insert 指令没问题,而 select 指令出现如下报错: com.microsoft.sqlserver.jdbc.SQLServerException: ')' 附近有语法错误。 at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:216) at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1515) at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:792) at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:689) at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696) at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715) at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:180) at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:155) at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeQuery(SQLServerStatement.java:616) at com.javaee.servletxm.comm.MSSQLJDBC.select(MSSQLJDBC.java:160) at com.javaee.servletxm.comm.MSSQLJDBC.select(MSSQLJDBC.java:195) at com.javaee.servletxm.comm.MSSQLJDBC.selectFirstValue(MSSQLJDBC.java:172) at com.javaee.servletxm.comm.MSSQLJDBC.getPageNumber(MSSQLJDBC.java:221) at com.javaee.servletxm.comm.MSSQLJDBC.selectByFY(MSSQLJDBC.java:259) at com.javaee.servletxm.kqgl.KqManager.getAllKqxx(KqManager.java:38) at com.javaee.servletxm.kqgl.Kqwh.doGet(Kqwh.java:47) at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) at javax.servlet.http.HttpServlet.service(HttpServlet.java:723) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:879) at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:617) at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1760) at java.lang.Thread.run(Thread.java:724) 这是具体的代码,求大神帮忙指正 package com.javaee.servletxm.comm; /** * jdbc下 SQL Server 2005 数据库的封装类 */ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.sql.CallableStatement; import java.sql.Connection; import java.sql.Date; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.List; import java.util.Properties; public class MSSQLJDBC { // 配置文件名称 private String iniFileName = MSSQLJDBC.class.getClassLoader().getResource("/com/javaee/servletxm/comm").getPath()+ "mssql.properties"; // 连接数据库 private String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; private String url = "jdbc:sqlserver://localhost;DatabaseName=jdms"; private String user = "sa"; private String password = ""; // 定义连接属性 private Connection connect = null; // 与连接有关三个通道 private Statement stmt = null; private PreparedStatement pstmt = null; private CallableStatement cstmt = null; public static final String stmtType = "stmt"; public static final String pstmtType = "pstmt"; public static final String cstmtType = "cstmt"; // 定义参数类型的静态常量值 public static final String varCharType = "varchar"; public static final String intType = "int"; public static final String doubleType = "decimal"; public static final String dateType = "datetime"; public static final String timeType = "timestamp"; // 定义全局的结果集 private ResultSet rs = null; // 在构造方法中对属性进行初始化赋值操作 public MSSQLJDBC() { // 读取配置文件 readIni(); // 初始化连接 initConnect(); } // 可配置文件 .properties // 读取配置文件 private void readIni() { File file = new File(iniFileName); if (!file.exists()) { // 创建一个文件 try { file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } // 判断文件是否有值 if (file.length() == 0) {// 说明是一个空文件 // 初始化值 try { Properties p = new Properties(); p.put("driver", driver); p.put("url", url); p.put("user", user); p.put("password", password); FileOutputStream fos = new FileOutputStream(file); p.store(fos, "配置文件信息"); fos.close(); } catch (IOException e) { e.printStackTrace(); } } else {// 如果有值 // 将信息读取出来 try { FileInputStream fis = new FileInputStream(file); Properties p = new Properties(); p.load(fis); this.driver = p.getProperty("driver"); this.url = p.getProperty("url"); this.user = p.getProperty("user"); this.password = p.getProperty("password"); fis.close(); } catch (IOException e) { e.printStackTrace(); } } } // 建立连接 private void initConnect() { try { Class.forName(driver); this.connect = DriverManager.getConnection(url, user, password); this.connect.setAutoCommit(false);// 设置手动提交事务 this.stmt = connect.createStatement(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } } /*/ 从tomcat缓冲池获取连接 private void initConnectFromDataSource() { try { InitialContext ic = new InitialContext(); DataSource ds = (DataSource) ic.lookup("java:comp/env/jdbc/oracleds"); this.connect = ds.getConnection(); this.connect.setAutoCommit(false); this.stmt = connect.createStatement(); } catch (NamingException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } }*/ // 需要调用者控制事务的两个方法 // 提交方法 private void commit() { try { this.connect.commit(); } catch (SQLException e) { e.printStackTrace(); } } // 回滚事务 private void rollBack() { try { this.connect.rollback(); } catch (SQLException e) { e.printStackTrace(); } } // 定义一组与操作有关的方法 // 使用普通通道执行的select public ResultSet select(String sql) { ResultSet prs = null; if (stmt != null) { try { prs = stmt.executeQuery(sql); } catch (SQLException e) { e.printStackTrace(); } } return prs; } // 根据传入的sql直接获取单一值 // 使用此方法的时候sql语句返回的单一的值 public String selectFirstValue(String sql, String type, List<String> csList) { String rstr = ""; rs = select(sql, type, csList);// 确定此结果集只有一条记录 if (rs != null) {// 说明结果集有值,且只有一条记录 try { ResultSetMetaData rsmd = rs.getMetaData(); if (rs.next()) { // 移动到第一条记录 String p_type = rsmd.getColumnTypeName(1); rstr = getResultSetValue(rs, 1, p_type); } } catch (SQLException e) { e.printStackTrace(); } } return rstr; } // 使用普通通道执行的select /** * sql 参数 type 使用通道的类型 stmt pstmt cstmt List<String> csList 预编通道执行的参数队列 * String 最少必须满足如下条件的字符串 数据类型 ,数据值 数据类型定义说明 字符串 数字(整数、小数) 日期(DATE、TIMESTAMP) */ public ResultSet select(String sql, String type, List<String> csList) { ResultSet prs = null; if (type.equals(stmtType)) {// 说明使用普通通道来执行 prs = select(sql); } else if (type.equals(pstmtType)) {// 说明使用预编译通道来执行 if (connect != null) { try { pstmt = connect.prepareStatement(sql); // 验证传入的参数和sql中的参数个数一致 setPrepareStatement(pstmt, csList);// 将参数设置进当前的预编译通道 prs = pstmt.executeQuery(); } catch (Exception e) { e.printStackTrace(); } } } return prs; } // 获取 总页数 public int getPageNumber(String sql, String type, List<String> csList, int pageSize) { // 处理总页数 int pageNumber = 0; // 第一步获取sql总记录数 String psql = "select count(*) from (" + sql + ")"; String result = selectFirstValue(psql, type, csList); int rows = 0; if (result != null && result.trim() != "") { rows = Integer.valueOf(result); } if (rows % pageSize == 0) { pageNumber = rows / pageSize; } else { pageNumber = rows / pageSize + 1; } return pageNumber; } /** * 自动添加分页查询方法 * * @param sql * 要执行的sql * @param type * 执行方式 * @param csList * 参数列表 * @param curPage * 当前页数 * @param pageSize * 每页记录数 默认为10 * @return */ public ResultSet selectByFY(String sql, String type, List<String> csList, int curPage, int pageSize) { ResultSet prs = null; // 处理 每页记录数 if (pageSize <= 0) { pageSize = 10;// 默认页面10条记录 } int pageNumber = getPageNumber(sql, type, csList, pageSize); // 处理当前页数 if (curPage < 0) { curPage = 1;// 默认第一页 } if (curPage > pageNumber) { curPage = pageNumber; } String psql = "select tmpaa.* from (select tmpa.*,(select (ROW_NUMBER() over (order by id))) as rn from (" + sql + ") tmpa where (select (ROW_NUMBER() over (order by id))) <= " + (curPage * pageSize) + ") tmpaa where tmpaa.rn >= " + ((curPage - 1) * pageSize + 1); prs = select(psql, type, csList); return prs; } // 将预编通道执行的参数队列按照指定规则设置进通道中 private void setPrepareStatement(PreparedStatement p, List<String> csList) throws Exception { if (csList != null && csList.size() > 0) { for (int i = 0; i < csList.size(); i++) { // 此处的str是数据类型 ,数据值 // 解析出数据类型和数据值 String[] s = csList.get(i).split(","); String sType = s[0]; String sData = s[1]; if (varCharType.equals(sType)) { p.setString(i + 1, sData); } else if (intType.equals(sType)) { p.setInt(i + 1, Integer.valueOf(sData)); } else if(doubleType.equals(sType)){ p.setDouble(i+1, Double.valueOf(sData)); } else if (dateType.equals(sType)) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); java.util.Date d = sdf.parse(sData); p.setDate(i + 1, new Date(d.getTime())); } else if (timeType.equals(sType)) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); java.util.Date d = sdf.parse(sData); p.setTimestamp(i + 1, new Timestamp(d.getTime())); } } } } // 定义一个执行insert update delete的方法 public int iudSql(String sql) { int ri = -1; if (stmt != null) { try { ri = stmt.executeUpdate(sql); commit(); } catch (SQLException e) { e.printStackTrace(); rollBack(); } } return ri; } public int iudSql(String sql, String type, List<String> csList) { int ri = -1; if (stmtType.equals(type)) { ri = iudSql(sql); } else if (pstmtType.equals(type)) { if (connect != null) { try { pstmt = connect.prepareStatement(sql); setPrepareStatement(pstmt, csList); ri = pstmt.executeUpdate(); commit(); } catch (Exception e) { e.printStackTrace(); rollBack(); } } } return ri; } /** * 编写一个通用的遍历ResultSet结果集的方法 */ public void iteratorResultSet(ResultSet rs) { try { if (rs != null) {// 说明有值 // ResultSetMetaData 此对象里封装了与结果集有关所有信息 // 此结果有几列组成,每列的列名,每列的数据类型 ResultSetMetaData rsmd = rs.getMetaData(); // 得到结果集列数 int columnCount = rsmd.getColumnCount(); // 输出此结果集的所有列名 for (int i = 1; i <= columnCount; i++) { System.out.print(rsmd.getColumnName(i) + "\t"); } System.out.println(""); // 遍历输出所有的数据 while (rs.next()) { // 如何在获取rs中的数据? for (int i = 1; i <= columnCount; i++) { String type = rsmd.getColumnTypeName(i); System.out.print(getResultSetValue(rs, i, type) + "\t"); } System.out.println(""); } } } catch (SQLException e) { e.printStackTrace(); } } // 从ResultSet中根据数据类型来得到数据值的方法 // 先处理常用的sqlserver的数据类型的对应 private String getResultSetValue(ResultSet rs, int index, String type) { String rstr = ""; try { if (rs != null && !"".equals(type) && index > 0) { if ("char".equals(type.trim()) || "varchar".equals(type.trim())) { if (rs.getString(index) != null) { rstr = rs.getString(index); } } else if ("int".equals(type.trim())) { rstr = rs.getInt(index) + ""; } else if ("decimal".equals(type.trim())) { rstr = String.valueOf(rs.getDouble(index)); } else if ("date".equals(type.trim())) { Date date = rs.getDate(index); if (date != null) { rstr = new SimpleDateFormat("yyyy年MM月dd日").format(date); } } else if ("timestamp".equals(type.trim()) || "datetime".equals(type.trim())) { Timestamp tt = rs.getTimestamp(index); if (tt != null) { rstr = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒").format(tt); } } } } catch (SQLException e) { e.printStackTrace(); } return rstr; } /* //统一事务管理的批量sql的封装 public boolean iudSql(List<String> sqlList){ int ri = -1; if(stmt!=null){ try { ri = stmt.executeUpdate(sql); commit(); } catch (SQLException e) { e.printStackTrace(); rollBack(); } } return ri; }*/ // 关闭连接 public void close() { try { // 关闭所有的与数据库有关的对象 if (rs != null) { rs.close(); rs = null; } if (stmt != null) { stmt.close(); stmt = null; } if (pstmt != null) { pstmt.close(); pstmt = null; } if (cstmt != null) { cstmt.close(); cstmt = null; } if (connect != null) { connect.close(); connect = null; } } catch (SQLException e) { e.printStackTrace(); } } }

用jsp删除数据库数据时数据库无返回。但是如果SQL语句直接写出变量,返回删除成功了。

<body> <% response.setContentType("text/html"); request.setCharacterEncoding("GBK"); response.setCharacterEncoding("GBK"); String name = new String(request.getParameter("name").getBytes("ISO-8859-1"),"GBK"); out.print(name); String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; //加载JDBC驱动 String dbURL = "jdbc:sqlserver://localhost:1433; DatabaseName=化妆品管理系统"; //连接服务器和数据库sample String userName = "sa"; //默认用户名 String userPwd = "123456"; //密码 Connection conn; Class.forName(driverName); conn = DriverManager.getConnection(dbURL, userName, userPwd); Statement stat = conn.createStatement(); String sql = "DELETE FROM customers WHERE customername ='郭海涛'"; int i = stat.executeUpdate(sql); out.println(i); %> ** "DELETE FROM customers WHERE customername ='郭海涛'";** 这样就可以删除成功。 ** "DELETE FROM customers WHERE customername ='name'";** 这样就删除不了。 但是打印出来name的值就是‘郭海涛’,没有乱码。

sql语句中出现了这样的错误怎么解决呀!

String sql = "select tab.nid,tab.tid,tab.pdate,tab.ptype,tab.psysdate,tab.pprice,tab.prodname," + "tab.auditstatus,tab.pnumber,tab.zprice,tab.companyId,tab.sno,tab.soeno,tab.provname from " + "(select n.id nid,t.id tid,n.P_DATE pdate,n.TYPE ptype,n.P_SYS_DATE psysdate,sum(t.P_PRICE) pprice," + "s.PRODNAME prodname,n.AUDIT_STATUS auditstatus,sum(t.P_NUMBER) pnumber," + "sum(Z_PRICE) zprice,n.COMPANY_ID companyId,s.no sno,s.oeno soeno,jtp.provname provname " + "from jxc_t_purchase as n " + "right join jxc_t_purchase_detail as t on t.P_PURCHASE_ID=n.id " + "left join jxc_t_products as s on s.id=t.P_WARES_ID " + "left join jxc_t_providers jtp on s.PROVIDER_ID = jtp.id " + "left join jxc_t_outbound_info jto on n.TYPE = jto.type " + "group by n.id desc ) tab where 1=1 "; 出现了这样的错误!Unknown column 'n.TYPE' in 'field list'

SQL中,添加一个条件后,执行效率瞬间下降,怎么优化

此SQL语句为查询数据库中,当前月,前一月,前两月数据,但是where中加了一个条件后,查找时间从2秒延长至50秒左右,请问造成这种状况的原因是什么?以及有什么优化方法? SELECT TR.RC_NO, TR.FEE_TYPE, TR.FISCAL_PERIOD,--月份 MIN (DATE_START) CUR_DATE_START, MAX (DATE_END) CUR_DATE_END, CONVERT(VARCHAR(30),CAST(SUM(ISNULL(FEE_ACTUAL,0))/ 10000 AS decimal(18,2)),1) AS CUR_FEE_ACTUAL, replace(SUBSTRING ( CAST (DATEADD(m ,- 1, CAST (TR.FISCAL_PERIOD + '01' AS DATE)) AS VARCHAR),1,7),'-','') AS PRE_FISCAL_PERIOD, PRE.PRE_DATE_START, PRE.PRE_DATE_END, PRE.PRE_FEE_ACTUAL, replace(SUBSTRING ( CAST (dateadd(m ,- 2, CAST (TR.FISCAL_PERIOD + '01' AS DATE)) AS VARCHAR),1,7),'-','') AS BEF_FISCAL_PERIOD, BEF.BEF_DATE_START, BEF.BEF_DATE_END, BEF.BEF_FEE_ACTUAL FROM T_AP_PAYMENT_REQUEST TR LEFT JOIN ( SELECT TP.RC_NO,TP.FEE_TYPE, TP.FISCAL_PERIOD, MIN (DATE_START) PRE_DATE_START, MAX (DATE_END) PRE_DATE_END, CONVERT(VARCHAR(30),CAST(SUM(ISNULL(FEE_ACTUAL,0))/ 10000 AS decimal(18,2)),1) AS PRE_FEE_ACTUAL FROM T_AP_PAYMENT_REQUEST TP WHERE IS_DELETE = '0' AND IS_AUTO_PAY = 'D00002' AND ISNULL(IS_FIRST_PAY, '') != 'D00002' AND PR_STATUS != 'L04301' GROUP BY TP.RC_NO, TP.FEE_TYPE, TP.FISCAL_PERIOD ) PRE ON PRE.RC_NO = TR.RC_NO AND PRE.FEE_TYPE=TR.FEE_TYPE LEFT JOIN ( SELECT TA.RC_NO,TA.FEE_TYPE, TA.FISCAL_PERIOD, MIN (DATE_START) BEF_DATE_START, MAX (DATE_END) BEF_DATE_END, CONVERT(VARCHAR(30),CAST(SUM(ISNULL(FEE_ACTUAL,0))/ 10000 AS decimal(18,2)),1) AS BEF_FEE_ACTUAL FROM T_AP_PAYMENT_REQUEST TA WHERE IS_DELETE = '0' AND IS_AUTO_PAY = 'D00002' AND ISNULL(IS_FIRST_PAY, '') != 'D00002' AND PR_STATUS != 'L04301' GROUP BY TA.RC_NO, TA.FEE_TYPE, TA.FISCAL_PERIOD ) BEF ON BEF.RC_NO = TR.RC_NO AND BEF.FEE_TYPE=TR.FEE_TYPE WHERE TR.FISCAL_PERIOD='201701' --此语句为添加的条件 AND PRE.FISCAL_PERIOD = replace(SUBSTRING (CAST (dateadd(m ,- 1,CAST (TR.FISCAL_PERIOD + '01' AS DATE)) AS VARCHAR),1,7),'-','') AND BEF.FISCAL_PERIOD = replace(SUBSTRING (CAST (dateadd(m ,- 2,CAST (TR.FISCAL_PERIOD + '01' AS DATE)) AS VARCHAR),1,7),'-','') AND TR.IS_DELETE = '0' AND TR.IS_AUTO_PAY = 'D00002' AND ISNULL(TR.IS_FIRST_PAY, '') != 'D00002' AND TR.PR_STATUS != 'L04301' GROUP BY TR.RC_NO, TR.FEE_TYPE, TR.FISCAL_PERIOD, PRE.PRE_DATE_START, PRE.PRE_DATE_END, PRE.PRE_FEE_ACTUAL, BEF.BEF_DATE_START, BEF.BEF_DATE_END, BEF.BEF_FEE_ACTUAL ORDER BY TR.RC_NO, TR.FEE_TYPE, TR.FISCAL_PERIOD 代码需要注释的,直接问就可以了

SQL插入日期始终为NULL

<div class="post-text" itemprop="text"> <p>I'm trying to use an upload page to insert into my database with the following code:</p> <pre><code>if($file!=="") { echo "&lt;br/&gt;".$file; $handle = fopen($file, "r"); $row = 0; $delete_records = mysql_query("DELETE FROM affiliationagreements"); $delete_records = mysql_query("DELETE FROM college"); $delete_records = mysql_query("DELETE FROM program"); $delete_records = mysql_query("DELETE FROM facility"); $delete_records = mysql_query("DELETE FROM submitor"); $delete_records = mysql_query("DELETE FROM location"); //will loop each record in the CSV file while(($fileop = fgetcsv($handle,1000,",")) !== false ) { //columns names of the CSV file are not needed if($row==0) { $row++; } else { //accept apostrophes in the strings $fileop = array_map("mysql_real_escape_string",$fileop); $sql = mysql_query("INSERT INTO affiliationagreements(id, AANumber, Facility, Submitor, Program, Location, College, SubmissionDate, Action, EffectiveDate, Status, ExpirationDate) VALUES('', '$fileop[0]', '$fileop[1]', '$fileop[2]', '$fileop[3]', '$fileop[4]', '$fileop[5]', '$fileop[11]', '$fileop[23]', '$fileop[24]', '$fileop[25]', '$fileop[26]') ")or die(mysql_error()); </code></pre> <p>To just give a sample, and when I upload my CSV file to add the values, I print them out in the console and see that the values are being read correctly and they are. But, once my php script ends and I return to the main page, my dates are all null. None of them are the values what are reflected in the csv file. Here is the schema for my database:</p> <pre><code>CREATE TABLE `affiliationagreements` ( `id` int(11) NOT NULL AUTO_INCREMENT, `AANumber` varchar(20) DEFAULT NULL, `Facility` varchar(150) DEFAULT NULL, `Submitor` varchar(50) DEFAULT NULL, `Program` varchar(60) DEFAULT NULL, `Location` varchar(50) DEFAULT NULL, `College` varchar(50) DEFAULT NULL, `SubmissionDate` date DEFAULT NULL, `Action` varchar(50) DEFAULT NULL, `EffectiveDate` date DEFAULT NULL, `Status` varchar(50) DEFAULT NULL, `ExpirationDate` date DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; </code></pre> <p>If I change SubmissionDate, EffectiveDate, and ExpirationDate to a varchar, they insert correctly but I can't use varchar because I am comparing date values. And Advice?</p> <p>***Update. In the CSV file, the format is MM/DD/YYYY. I didn't think this would be a problem. Would it be better to change this? And I'm deleting records because my boss wanted the DB cleared before a file was reuploaded since the uploaded file was an update of the previously uploaded one. ****</p> </div>

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

程序员请照顾好自己,周末病魔差点一套带走我。

程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。

和黑客斗争的 6 天!

互联网公司工作,很难避免不和黑客们打交道,我呆过的两家互联网公司,几乎每月每天每分钟都有黑客在公司网站上扫描。有的是寻找 Sql 注入的缺口,有的是寻找线上服务器可能存在的漏洞,大部分都...

搜狗输入法也在挑战国人的智商!

故事总是一个接着一个到来...上周写完《鲁大师已经彻底沦为一款垃圾流氓软件!》这篇文章之后,鲁大师的市场工作人员就找到了我,希望把这篇文章删除掉。经过一番沟通我先把这篇文章从公号中删除了...

总结了 150 余个神奇网站,你不来瞅瞅吗?

原博客再更新,可能就没了,之后将持续更新本篇博客。

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

优雅的替换if-else语句

场景 日常开发,if-else语句写的不少吧??当逻辑分支非常多的时候,if-else套了一层又一层,虽然业务功能倒是实现了,但是看起来是真的很不优雅,尤其是对于我这种有强迫症的程序"猿",看到这么多if-else,脑袋瓜子就嗡嗡的,总想着解锁新姿势:干掉过多的if-else!!!本文将介绍三板斧手段: 优先判断条件,条件不满足的,逻辑及时中断返回; 采用策略模式+工厂模式; 结合注解,锦...

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

2020阿里全球数学大赛:3万名高手、4道题、2天2夜未交卷

阿里巴巴全球数学竞赛( Alibaba Global Mathematics Competition)由马云发起,由中国科学技术协会、阿里巴巴基金会、阿里巴巴达摩院共同举办。大赛不设报名门槛,全世界爱好数学的人都可参与,不论是否出身数学专业、是否投身数学研究。 2020年阿里巴巴达摩院邀请北京大学、剑桥大学、浙江大学等高校的顶尖数学教师组建了出题组。中科院院士、美国艺术与科学院院士、北京国际数学...

男生更看重女生的身材脸蛋,还是思想?

往往,我们看不进去大段大段的逻辑。深刻的哲理,往往短而精悍,一阵见血。问:产品经理挺漂亮的,有点心动,但不知道合不合得来。男生更看重女生的身材脸蛋,还是...

程序员为什么千万不要瞎努力?

本文作者用对比非常鲜明的两个开发团队的故事,讲解了敏捷开发之道 —— 如果你的团队缺乏统一标准的环境,那么即使勤劳努力,不仅会极其耗时而且成果甚微,使用...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试:第十六章:Java中级开发(16k)

HashMap底层实现原理,红黑树,B+树,B树的结构原理 Spring的AOP和IOC是什么?它们常见的使用场景有哪些?Spring事务,事务的属性,传播行为,数据库隔离级别 Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的优点,MyBatis框架的优点 SpringCould组件有哪些,他们...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

《Oracle Java SE编程自学与面试指南》最佳学习路线图2020年最新版(进大厂必备)

正确选择比瞎努力更重要!

《Oracle Java SE编程自学与面试指南》最佳学习路线图(2020最新版)

正确选择比瞎努力更重要!

都前后端分离了,咱就别做页面跳转了!统统 JSON 交互

文章目录1. 无状态登录1.1 什么是有状态1.2 什么是无状态1.3 如何实现无状态1.4 各自优缺点2. 登录交互2.1 前后端分离的数据交互2.2 登录成功2.3 登录失败3. 未认证处理方案4. 注销登录 这是本系列的第四篇,有小伙伴找不到之前文章,松哥给大家列一个索引出来: 挖一个大坑,Spring Security 开搞! 松哥手把手带你入门 Spring Security,别再问密...

字节跳动面试官竟然问了我JDBC?

轻松等回家通知

面试官:你连SSO都不懂,就别来面试了

大厂竟然要考我SSO,卧槽。

阿里面试官让我用Zk(Zookeeper)实现分布式锁

他可能没想到,我当场手写出来了

终于,月薪过5万了!

来看几个问题想不想月薪超过5万?想不想进入公司架构组?想不想成为项目组的负责人?想不想成为spring的高手,超越99%的对手?那么本文内容是你必须要掌握的。本文主要详解bean的生命...

自从喜欢上了B站这12个UP主,我越来越觉得自己是个废柴了!

不怕告诉你,我自从喜欢上了这12个UP主,哔哩哔哩成为了我手机上最耗电的软件,几乎每天都会看,可是吧,看的越多,我就越觉得自己是个废柴,唉,老天不公啊,不信你看看…… 间接性踌躇满志,持续性混吃等死,都是因为你们……但是,自己的学习力在慢慢变强,这是不容忽视的,推荐给你们! 都说B站是个宝,可是有人不会挖啊,没事,今天咱挖好的送你一箩筐,首先啊,我在B站上最喜欢看这个家伙的视频了,为啥 ,咱撇...

代码注释如此沙雕,会玩还是你们程序员!

某站后端代码被“开源”,同时刷遍全网的,还有代码里的那些神注释。 我们这才知道,原来程序员个个都是段子手;这么多年来,我们也走过了他们的无数套路… 首先,产品经理,是永远永远吐槽不完的!网友的评论也非常扎心,说看这些代码就像在阅读程序员的日记,每一页都写满了对产品经理的恨。 然后,也要发出直击灵魂的质问:你是尊贵的付费大会员吗? 这不禁让人想起之前某音乐app的穷逼Vip,果然,穷逼在哪里都是...

立即提问
相关内容推荐