正常的传递  @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. codeforces 372 Complete the Word(双指针)

    codeforces 372 Complete the Word(双指针) 题链 题意:给出一个字符串,其中'?'代表这个字符是可变的,要求一个连续的26位长的串,其中每个字母都只出现一次 #incl ...

  2. 【Codeforces 992B】Nastya Studies Informatics

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 因为gcd(a,b)=x 所以设a = nx b = mx 又有ab/gcd(a,b)=lcm(a,b)=y 则nmx = y 即n(m*x) ...

  3. zoj 1008 暴力枚举求解dfs+优化

    /* 现将相同的合并计数. 再枚举判断是否符合当cou==n*n是符合就退出 */ #include<stdio.h> #include<string.h> #define N ...

  4. 爬虫——使用ItemLoader维护item

    在item的Filed()中设置参数函数,可以用来预处理item字段的数据,另一方面也方便程序代码的管理和重用 item中 from scrapy.loader.processors import M ...

  5. tyvj1117 拯救ice-cream

      背景 天好热……Tina顶着那炎炎的烈日,向Ice-cream home走去……可是……停电了……冰淇淋们躺在Ice-cream home的冰柜里,慢慢地……慢慢地……融化…………你说,她能赶在冰 ...

  6. poj 3074

    题意:解数独 分析: 完整的数独有四个充要条件: 1.每个格子都有填数字 2.每列都有1~9中的每个数字 3.每行都有1~9中的每个数字 4.每个9宫格都有1~9中的每个数字 可以转化成精确覆盖问题. ...

  7. 为 Windows Phone 8.1 app 解决“The type does not support direct content.”的问题

    我在 VS 14 CTP 中新建了一个空的 app store 项目名叫 PlayWithXaml ,项目的 MainPage.xaml 文件改为了以下内容: <Page x:Class=&qu ...

  8. VS2017 +NetCore2.2.0+WebApi项目整合SwaggerUI 以及遇到的坑

    1.新建一个WebApi项目,这里不说了. 2.打开项目nuget管理控制台,在 https://www.nuget.org/ 搜索swagger的包:Swashbuckle.AspNetCore , ...

  9. 《WF in 24 Hours》读书笔记 - Hour 3(1) - Workflow:添加宿主和事件监听

    1. 创建项目组,并添加一个Console Project和Activity Library,在Activity Library的项目中添加CodeActivity1和CodeActivity2,最终 ...

  10. [Algorithm] Determine if two strings are an anagram

    The anagram test is commonly used to demonstrate how an naive implementation can perform significant ...