求助:关于嵌入sql语句in的用法(动态sql)
在输入供应商编码后,需要判断该供应商是否属于权限门店,写动态sql
s_sql='select sup_code,sup_desc,man_type,cont_code,founded_time,determine_timecen_person,stat_flag,abc_class from supplier where sup_code="'+supcode+'" and shop_own in ('+ls_shop+')'
declare cur_shop dynamic cursor for sqlsa;
prepare sqlsa from :ls_sql;
open dynamic cur_shop;
fetch cur_shop into :supcode,:supdesc,:mantype,:contcode,:foundeddate,:determinedate,:enrolperson,:statflag,:abcclass;
close cur_shop;
lS_shop是我已经做好的门店字符串,但是发现不在该门店的供应商也能查出来
用sqlserver事件查看器跟踪了一下,代码如下:
declare @P1 int
set @P1=0
declare @P2 int
set @P2=2
declare @P3 int
set @P3=0
exec sp_cursoropen @cursor = @P1 output, @stmt = 'select sup_code,sup_desc,man_type,cont_code,founded_time,determine_timecen_person,stat_flag,abc_class from supplier where sup_code="80381" and shop_own in ("002","003","004","005","006")', @scrollopt = @P2 output, @ccopt = 4, @rows = @P3 output
select @P1, @P2, @P3
80381供应商是门店001的,也就是不在in条件下的任何一个门店,为什么还会查出来呢?
s_sql='select sup_code,sup_desc,man_type,cont_code,founded_time,determine_timecen_person,stat_flag,abc_class from supplier where sup_code="'+supcode+'" and shop_own in ('+ls_shop+')'
declare cur_shop dynamic cursor for sqlsa;
prepare sqlsa from :ls_sql;
open dynamic cur_shop;
fetch cur_shop into :supcode,:supdesc,:mantype,:contcode,:foundeddate,:determinedate,:enrolperson,:statflag,:abcclass;
close cur_shop;
lS_shop是我已经做好的门店字符串,但是发现不在该门店的供应商也能查出来
用sqlserver事件查看器跟踪了一下,代码如下:
declare @P1 int
set @P1=0
declare @P2 int
set @P2=2
declare @P3 int
set @P3=0
exec sp_cursoropen @cursor = @P1 output, @stmt = 'select sup_code,sup_desc,man_type,cont_code,founded_time,determine_timecen_person,stat_flag,abc_class from supplier where sup_code="80381" and shop_own in ("002","003","004","005","006")', @scrollopt = @P2 output, @ccopt = 4, @rows = @P3 output
select @P1, @P2, @P3
80381供应商是门店001的,也就是不在in条件下的任何一个门店,为什么还会查出来呢?
...全文
相关推荐
sql语句妙用,各种sql语句的详细用法与讲解
本篇内容主要涉及SQL语句的详细用法,特别是动态SQL的运用,这对于编写流畅的程序至关重要。1. 动态SQL语句: 动态SQL允许在执行时构建SQL命令,这在需要根据变量或用户输入构建查询时非常有用。
SQLServer动态SQL语句的用法
SQL Server 动态 SQL 语句的用法SQL Server 中的动态 SQL 语句是一种灵活的查询方式,它可以根据不同的情况生成不同的 SQL 语句。
Mybatis模糊查询和动态sql语句的用法
Mybatis模糊查询和动态sql语句的用法Mybatis是当前最流行的Java持久层框架之一,它提供了强大的数据库交互功能,包括模糊查询和动态sql语句的支持。
sql语句优化之用EXISTS替代IN、用NOT EXISTS替代NOT IN的语句
SQL语句优化之用EXISTS替代IN、用NOT EXISTS替代NOT IN的语句SQL语句优化是数据库性能优化的重要方面之一。
SQL中in参数化的用法
SQL 中 IN 参数化的用法详解在 SQL 中,对于 IN 操作符的使用是非常常见的,特别是在 WHERE 子句中规定多个值时。


脚本语言
