谁来帮我写这个的正则
源语句是
SELECT Top 10 PE_Nodes.* FROM PE_Nodes WHERE NodeID NOT IN (SELECT TOP 0 NodeID FROM PE_Nodes where ParentID = 2 and NodeType=1 order by OrderID) and (ParentID = 2) and NodeType=1 order by OrderID
将红色的语句去掉 变成这样的
--------------------编程问答-------------------- 在sql中写个存储过程用replace,用什么正则啊 --------------------编程问答-------------------- SELECT TOP 0 第一次看到,长见识了,不知道有何作用。
SELECT Top 10 PE_Nodes.* FROM PE_Nodes WHERE (ParentID = 2) and NodeType=1 order by OrderID
sql好像没有正则,最多就是like
恕我愚昧,不怎么明白楼主的意思~ --------------------编程问答-------------------- SQL中能用正则的吗? --------------------编程问答--------------------
\[.*?\]
替换为空就行了 --------------------编程问答-------------------- 不好意思,看错应该是这样
--------------------编程问答-------------------- 呵呵 --------------------编程问答--------------------
\[color=.*?\][^[]*\[/color\]
--------------------编程问答-------------------- --------------------编程问答-------------------- 在程序里替换,数据库是ACCESS 使用top 0 会出错
string source="SELECT Top 10 PE_Nodes.* FROM PE_Nodes WHERE NodeID NOT IN (SELECT TOP 0 NodeID FROM PE_Nodes where ParentID = 2 and NodeType=1 order by OrderID) and (ParentID = 2) and NodeType=1 order by OrderID";
string result=System.Text.RegularExpressions.Regex.Replace(source,"\\[color=.*?\\][^[]*\\[/color\\]","");
//Console.Write(result);
这是分页SQL,在读取第一页的时候会出错,现在想用正则替换到中间那部分 --------------------编程问答-------------------- top 0 不是取表结构的吗? --------------------编程问答-------------------- 在SQL SERVER中用SELECT TOP 0 * FROM TABLE1 可以返回表TABLE1的字段名。 --------------------编程问答-------------------- --------------------编程问答--------------------
能不能看我的回复再说 --------------------编程问答-------------------- 用正则是因为中间的语句不是固定的,也可能是别的字段,但是 not in ()这个结构是肯定的,所以才想这么用 --------------------编程问答--------------------
正解 --------------------编程问答--------------------
--------------------编程问答-------------------- SQL中可以使用正则,用正则操作比较容易。。。。 --------------------编程问答-------------------- 写个存储过程:
DECLARE @temp varchar(500)
declare @value varchar(500)
set @temp='SELECT Top 10 PE_Nodes.* FROM PE_Nodes WHERE NodeID NOT IN (SELECT TOP 0 NodeID FROM PE_Nodes where ParentID = 2 and NodeType=1 order by OrderID) and (ParentID = 2) and NodeType=1 order by OrderID'
select replace(@temp,substring(@temp,patindex('%[]%',@temp)-13,patindex('%[]%',@temp)-patindex('%[]%',@temp)+15),'')
select substring(@temp,patindex('%[[color=#FF0000]]%',@temp)-13,patindex('%[]%',@temp)-patindex('%[]%',@temp)+15)
结果:
SELECT Top 10 PE_Nodes.* FROM PE_Nodes WHERE (ParentID = 2) and NodeType=1 order by OrderID
[color=#FF0000]NodeID NOT IN (SELECT TOP 0 NodeID FROM PE_Nodes where ParentID = 2 and NodeType=1 order by OrderID) and
以下是最通俗易懂的写法(个人认为)
CREATE procedure AAA
@status int //状态 0 OR 1
AS
declare @SqlWhere varchar(1000)
declare @sql varchar(1000)
if @status=0 //条件1
begin
set @Sql='SELECT Top 10 PE_Nodes.* FROM PE_Nodes WHERE NodeID NOT IN (SELECT TOP 0 NodeID FROM PE_Nodes where ParentID = 2 and NodeType=1 order by OrderID) and (ParentID = 2) and NodeType=1 order by OrderID'
end
if @status=1 //条件2
begin
set @Sql='SELECT Top 10 PE_Nodes.* FROM PE_Nodes WHERE (ParentID = 2) and NodeType=1 order by OrderID'
end
Exec sp_executesql @sql
--------------------编程问答--------------------
--------------------编程问答-------------------- SQL中有正则么? 我只知道有通配符!学习 --------------------编程问答-------------------- .*?
private static string FilterStr(string p)
{
return System.Text.RegularExpressions.Regex.Replace(p, @"\[color=.*?\][^[]*\[/color\]", "");
}
补充:.NET技术 , ASP.NET