SqlSever not in条件中如何加入字符串(小弟新手,请大哥帮忙)

DLnetchengxuyuan 2012-07-29 07:16:52
各位大哥小弟是新手,遇到个问题,帮帮忙吧!!!

declare @ss varchar(50);
set @ss='1,2,3,4';
delete from ClassTable where ClassId not in (@ss);





各位大哥,假如我只想删除ClassTable表中 ClassId=5 的记录,可是现在却把 classId=1, 2 , 3 4 的记录都删除了

该怎么办呢???
...全文
412 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
DLnetchengxuyuan 2012-07-30
  • 打赏
  • 举报
回复
大哥们,原本我的需求是

注(两个表有外键关系)
删除ClassTable中的记录 条件ClassId not in 1,2,3,4
同时删除StudnetTable中的记录 条件 ClassId not in 1,2,3,4

虽然可以在c#中写两条delete语句执行,但是小弟现在想用 数据库中的存储过程来解决。。。。请各位大哥指导。。。 小弟谢谢你们了。。。
gaobinbinbin 2012-07-30
  • 打赏
  • 举报
回复

declare @ss varchar(20)
set @ss='2'
declare @sql varchar(100)
set @sql=''
set @sql='delete from course where C# in ('+@ss+')'
exec(@sql)
gaobinbinbin 2012-07-30
  • 打赏
  • 举报
回复

declare @ss varchar(20)
set @ss='2'
declare @sql varchar(100)
set @sql=''
set @sql='delete from course where C# in ('+@ss+')'
exec(@sql)
gaobinbinbin 2012-07-30
  • 打赏
  • 举报
回复

declare @ss varchar(20)
set @ss='2'
declare @sql varchar(100)
set @sql=''
set @sql='delete from course where C# in ('+@ss+')'
exec(@sql)
xinguohit 2012-07-30
  • 打赏
  • 举报
回复
set @ss='5';
delete from ClassTable where ClassId in (@ss);
这么写呢?
DLnetchengxuyuan 2012-07-30
  • 打赏
  • 举报
回复
还是没有成功
lzly0812 2012-07-30
  • 打赏
  • 举报
回复
delete from ClassTable where ClassId not in (+quotename(@NotClassId,'''')+)
delete from StudentTable where ClassId not in (+quotename(@NotClassId,'''')+)
这样试一试
DLnetchengxuyuan 2012-07-29
  • 打赏
  • 举报
回复
这么写,就出错了。。。
DLnetchengxuyuan 2012-07-29
  • 打赏
  • 举报
回复
大哥,小弟原本 是想用到存储过程中的,那么这样行吗

if(exists(select * from sys.objects where name='proc_delete_class_student'))
drop proc proc_delete_class_student
go
create proc proc_delete_class_student(
@NotClassId nvarchar(max)
)
as
delete from ClassTable where ClassId not in (+@NotClassId+)
delete from StudentTable where ClassId not in (+@NotClassId+)
DLnetchengxuyuan 2012-07-29
  • 打赏
  • 举报
回复
谢谢你,大哥。。。。
人生无悔 2012-07-29
  • 打赏
  • 举报
回复

declare @ss varchar(50),@sql varchar(max);
set @ss='1,2,3,4';
set @sql='delete from ClassTable where ClassId not in ('+@ss+')';
exec(@sql);
--@ss是字符串,你那样写是按一个字符串'1,2,3,4'而不是一个集合
DLnetchengxuyuan 2012-07-29
  • 打赏
  • 举报
回复
各位大哥,帮帮忙吧
内容概要:本文研究了基于Benders分解算法与输电网-配电网运营商(TSO-DSO)协调机制的双层优化模型,旨在有效应对新能源出力波动、负荷不确定性等对现代电力系统运行带来的挑战。模型上层由输电网运营商(TSO)负责全局资源优化与主网稳定性调控,下层由多个配电网运营商(DSO)实现本地分布式能源的灵活调度,通过Benders分解实现上下层之间的迭代协调与信息交互,从而在保障系统安全的前提下提升整体运行的经济性与鲁棒性。研究提供了完整的Matlab代码实现,涵盖数学建模、算法求解、收敛性分析及仿真结果可视化等环节,有助于深入理解双层优化架构在输配电网协同调度的具体应用与技术细节。; 适合人群:具备电力系统分析、优化理论基础及一定Matlab编程能力的研究生、科研人员,以及从事电网调度、能源系统规划等相关领域的工程技术人员。; 使用场景及目标:①掌握Benders分解在电力系统双层优化问题的建模与求解流程;②理解TSO-DSO协同机制下输配电网交互建模的核心思想与实现方法;③复现并拓展高水平学术论文的优化模型,服务于科研项目攻关或实际工程仿真需求。; 阅读建议:建议结合凸优化理论、电力系统经济调度与Benders分解原理进行系统学习,优先运行并调试所提供的Matlab代码,调整关键参数以观察算法收敛行为与模型性能变化,从而深化对协调机制与优化机理的理解。

34,876

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧