正常的传递  @SendStationID='''1'',''2''' 是无效,改用 @SendStationID='1,2,3,003,002' 调用以下的存储过程可以实现in 查询效果

USE [ztwl]
GO
/****** Object: StoredProcedure [dbo].[SelectPage_StationTransferFee_Second] Script Date: 04/11/2019 14:17:37 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO ALTER PROCEDURE [dbo].[SelectPage_StationTransferFee_Second] @begincount varchar(50), --开始条数
@PageSize varchar(50) , --每页多少条记录
@Where nvarchar(4000) =N'' , --条件语句
@StartStationID varchar(50), --始发分拨网点
@SendStationID varchar(4000), --发站网点
@InStationID varchar(50) --入库网点 as
BEGIN --------begin--组合发站参数临时表-----begin-----
DECLARE @Temp_Array varchar(max)
set @Temp_Array=@SendStationID
declare @Temp_Variable varchar(max)
create table #Temp_SendTable(Item varchar(max)) ---定义发站ID临时表
while(LEN(@Temp_Array) > 0)
begin if(CHARINDEX(',',@Temp_Array) = 0)
begin set @Temp_Variable = @Temp_Array
set @Temp_Array = ''
end else begin set @Temp_Variable = LEFT(@Temp_Array,CHARINDEX(',',@Temp_Array)-1)
set @Temp_Array = RIGHT(@Temp_Array,LEN(@Temp_Array)-LEN(@Temp_Variable)-1)
end insert into #Temp_SendTable(Item) values(@Temp_Variable) end

------------组合发站参数------end-------------------- --- 第一部分:区域网点中转费 SELECT * INTO #Bas_FN_Area_StationConfig_Temp FROM (SELECT * from Bas_FN_Area_StationConfig_Daily WHERE 1=2 ) as x --1.1用始发分拨+发站网点+入库网点查询区域网点中转费报表;
IF LEN(@StartStationID)>0
BEGIN Insert into #Bas_FN_Area_StationConfig_Temp
SELECT * from Bas_FN_Area_StationConfig_Daily WHERE UpBelongCenterID= @StartStationID
and exists(select 1 from #Temp_SendTable(nolock) where #Temp_SendTable.Item=StartStationID) and InStationID=@InStationID and IfDel=0
-- PRINT '有--始发分拨查询'
end
else
BEGIN
Insert into #Bas_FN_Area_StationConfig_Temp
SELECT * from Bas_FN_Area_StationConfig_Daily WHERE exists(select 1 from #Temp_SendTable(nolock) where #Temp_SendTable.Item=StartStationID) and InStationID=@InStationID and IfDel=0
-- PRINT '无--始发分拨查询'
end --1.2创建已有的+产品列表临时表
SELECT * INTO #cityList_Temp FROM (SELECT a.FinalPlaceCityID , a.FinalPlaceCity,a.ProductID from #Bas_FN_Area_StationConfig_Temp a ) AS y
-- SELECT * from #Bas_FN_Area_StationConfig_Temp
--- 第二部分:网点中转费 --1.2发站网点+入库网点询+排除网点中转费重复的城市和产品
SELECT * INTO #Bas_FN_StationConfig_Temp FROM (
SELECT * from Bas_FN_StationConfig a WHERE exists(select 1 from #Temp_SendTable(nolock) where #Temp_SendTable.Item=a.UpStationID) and a.StartStationID=@InStationID and a.IfDel=0
and NOT EXISTS (SELECT b.FinalPlaceCityID from #cityList_Temp b WHERE a.FinalPlaceCityID=b.FinalPlaceCityID and a.ProductID=b.productID )
) as xx -- select count(*) from #cityList_Temp --1.3 合并区域和网点费用 UpBelongCenterID,UpBelongCenter,QuoteBelongCenterID,QuoteBelongCenter, SELECT * INTO #Bas_FN_StationConfig_Finally_Temp FROM
(
SELECT AreaCode,AreaName,StartStation as UpStation ,StartStationID as UpStationID ,InStation as StartStation ,InStationID as StartStationID,FinalPlaceCity,FinalPlaceCityID,FinalPlaceProvince,FinalPlaceProvinceID ,Product,ProductID,
InOutType,Limit,StartWeightOne,EndWeightOne,WeightPriceOne,VolumnPriceOne,StartWeightTwo,EndWeightTwo,WeightPriceTwo,VolumnPriceTwo,StartWeightThree,EndWeightThree,WeightPriceThree,VolumnPriceThree,StartWeightFour,EndWeightFour,WeightPriceFour,VolumnPriceFour,StartWeightFive,EndWeightFive,WeightPriceFive,VolumnPriceFive,StartWeightSix,EndWeightSix,WeightPriceSix,VolumnPriceSix,
UpBelongCenterID, UpBelongCenter, QuoteBelongCenterID, QuoteBelongCenter
from #Bas_FN_Area_StationConfig_Temp
UNION ALL
SELECT '' AS AreaCode,'' as AreaName, UpStation,UpStationID,StartStation,StartStationID,FinalPlaceCity,FinalPlaceCityID,FinalPlaceProvince,FinalPlaceProvinceID ,Product,ProductID,
CASE Status WHEN 0 THEN '出港网点中转费' ELSE '进港网点中转费' END as InOutType,Limit,StartWeightOne,EndWeightOne,WeightPriceOne,VolumnPriceOne,StartWeightTwo,EndWeightTwo,WeightPriceTwo,VolumnPriceTwo,StartWeightThree,EndWeightThree,WeightPriceThree,VolumnPriceThree,StartWeightFour,EndWeightFour,WeightPriceFour,VolumnPriceFour,StartWeightFive,EndWeightFive,WeightPriceFive,VolumnPriceFive,StartWeightSix,EndWeightSix,WeightPriceSix,VolumnPriceSix,b.BelongCenterID as UpBelongCenterID,b.BelongCenter as UpBelongCenter,c.BelongCenterID as QuoteBelongCenterID,c.BelongCenter as QuoteBelongCenter
FROM
(SELECT a.*,
(SELECT top 1 aa.EndStationID from Bas_FinalPlace aa WHERE aa.ifDelID=0 AND aa.QuoteCityID=a.FinalPlaceCityID) as EndStationID
from #Bas_FN_StationConfig_Temp a ) as aaa
LEFT JOIN Bas_StationInformation b on aaa.UpStationID=b.StationID and b.IfDel=0
LEFT JOIN Bas_StationInformation c on aaa.EndStationID=c.StationID and c.IfDel=0
) AS xyz --分页
DECLARE @sql nvarchar(4000)
set @sql=' select * from ( SELECT top '+@PageSize+' ROW_NUMBER() Over(order by AreaCode desc ) as rownumid, a.* from #Bas_FN_StationConfig_Finally_Temp a '+@where+' ) as pagetable where rownumid>'+@begincount
PRINT @sql
EXEC(@sql)
--总数
set @sql=' SELECT COUNT(*) from #Bas_FN_StationConfig_Finally_Temp '+@where+''
EXEC(@sql) DROP TABLE #Bas_FN_Area_StationConfig_Temp
DROP TABLE #cityList_Temp
DROP TABLE #Bas_FN_StationConfig_Temp
DROP TABLE #Bas_FN_StationConfig_Finally_Temp
DROP TABLE #Temp_SendTable
END

  

SQL SERVER中存储过程IN 参数条件的使用!!!的更多相关文章

  1. SQL Server中存储过程比直接运行SQL语句慢的原因

    原文:SQL Server中存储过程比直接运行SQL语句慢的原因 在很多的资料中都描述说SQLSERVER的存储过程较普通的SQL语句有以下优点: 1.       存储过程只在创造时进行编译即可,以 ...

  2. SQL Server中存储过程 比 直接运行SQL语句慢的原因

    问题是存储过程的Parameter sniffing     在很多的资料中都描述说SQLSERVER的存储过程较普通的SQL语句有以下优点: 1. 存储过程只在创造时进行编译即可,以后每次执行存储过 ...

  3. SQL Server中存储过程与函数的区别

    本质上没区别.只是函数有如:只能返回一个变量的限制.而存储过程可以返回多个.而函数是可以嵌入在sql中使用的,可以在select中调用,而存储过程不行.执行的本质都一样. 函数限制比较多,比如不能用临 ...

  4. 关于SQL Server中存储过程在C#中调用的简单示例

    目录 0. 简介 1. 语法细节 2. 示例1:模拟转账 3. 示例2:测试返回DataTable 4. 源代码下载 shanzm-2020年5月3日 23:23:44 0. 简介 [定义]:存储过程 ...

  5. SQL Server中存储过程的创建命令

    Create Proc 存储过程名称 ( @参数1 参数类型, @参数2 参数类型, ... ... --最后一行参数,别加逗号了,加逗号的意思是表示后面还有参数 ) AS 需要执行的SQL命令 GO ...

  6. SQL Server 中存储过程的练习

    建库建表建约束 插入数据 --建库建表建约束和插入测试数据 use bankDB go --1.完成存款,取款业务--存款 create proc usp_takeMoney ),),)=null,@ ...

  7. 【SQL】SQL Server中存储过程的调试方法

    1.以管理员用户登录DB服务器,把域用户追加到「Administrators」组. 2.在本机上以域用户登录,启动VS. 3.追加DB连接 4.右击要debug的存储过程,选择「ストアドプロシージャに ...

  8. SQL Server中对存储过程的理解

    数据库的存储过程理解为,处理数据的子程序,写起来像函数,用起来像函数,在SQL Server中存储过程分为两大类,系统的和自定义的,系统的都放在master系统数据库中,自定义就是自己去写的,用DDL ...

  9. 在易语言中调用MS SQL SERVER数据库存储过程方法总结

    Microsoft SQL SERVER 数据库存储过程,根据其输入输出数据,笼统的可以分为以下几种情况或其组合:无输入,有一个或多个输入参数,无输出,直接返回(return)一个值,通过output ...

随机推荐

  1. [luoguP2038] 无线网络发射器选址(模拟)

    传送门 又是个模拟水题,考虑边界就好,连long long都不用开. ——代码 #include <cstdio> #include <iostream> int n, d, ...

  2. BAT、网易、京东等如何做大数据风控的?

    大数据风控目前应该是前沿技术在金融领域的最成熟应用,相对于智能投顾.区块链等还在初期的金融科技应用,大数据风控目前已经在业界逐步普及,从BATJ这样的大企业,到交易规模比较大的网贷平台,再到做现金贷. ...

  3. HDU——2588 GCD

    题目大意: 求1~N中与N的最大公约数大于M的个数 思路: 这个题是不是可以想到暴力枚举??对于每一组数据枚举与他的最大公约数大于m的数的个数. 是,这种做法没错误,但是保准你T成狗.... 我们至少 ...

  4. AbstractList 重写 equals() 方法

    题目内容 题目内容很简单,就是创建 ArrayList 和 Vector 集合,向两者添加相同内容的字符串,最后用 equals() 方法比较是否相等. 这里就考察了 "==" 和 ...

  5. Sublime Text 3显示文本编码

    在Settings上加入"show_encoding":true 进入这个选项:[Preferences]->[Settings] 搞定之后,在右下角可以看见文本编码

  6. Eclipse错误出现:Unable to install breakpoint in... (未能解决)

    Unable to install breakpoint in... Eclipse Unable to install breakpoint in  的问题还是没解决 1.重装eclipse无效 2 ...

  7. SQL SERVE BASE

    http://www.cnblogs.com/chillsrc/category/49632.html

  8. 此人牛b,学习榜样

    http://liyangliang.me/about/ ------------------------------------------------------------2017年11月12日 ...

  9. webservice Connection timed out

    webservice Connection timed out,当发生webservice的链接超时错误时.我想原因无非就是webclient到webservice之间的链接通路发生了异常,那么该怎样 ...

  10. HDU 1242 -Rescue (双向BFS)&amp;&amp;( BFS+优先队列)

    题目链接:Rescue 进度落下的太多了,哎╮(╯▽╰)╭,渣渣我总是埋怨进度比别人慢...为什么不试着改变一下捏.... 開始以为是水题,想敲一下练手的,后来发现并非一个简单的搜索题,BFS做肯定出 ...