SQL查询条件生成小工具

时间:2023-03-09 06:19:40
SQL查询条件生成小工具

最近运维数据,经常遇到需要在sql条件中个In('',''....)个字符串的情况,于是在网上找了个小工具改造一下,先用着;

效果如图:

SQL查询条件生成小工具SQL查询条件生成小工具

 using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Utilities;
using Newtonsoft.Json; namespace ConsolePro
{
public class FileHelper
{
#region txt \r\n 给txt 文本 批量加',' 作为sql查询条件
public static void CreateSQLContidion()
{
var filePath = "D:\\rt.txt";
int TotalCountInEveryFile = ;
List<string> gotStrings = GetStreamMethod(filePath);
//Console.WriteLine(string.Join("\n", gotStrings.ToArray()));
if (gotStrings != null)
{
int fileCount = ;
for (int i = ; i < gotStrings.Count; i++)
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat("{0}\r\n", ("'" + gotStrings[i].Trim() + "',"));
if (i + < gotStrings.Count)
{
i++;
}
else
{
WriteStreamMethod(string.Format("d:\\Document{0}.txt", fileCount), sb.ToString());
return;
}
while (i % TotalCountInEveryFile != )
{
sb.AppendFormat("{0}\r\n", ("'" + gotStrings[i].Trim() + "',"));
if (i != gotStrings.Count - )
{
i++;
}
else
{
WriteStreamMethod(string.Format("d:\\Document{0}.txt", fileCount), sb.ToString());
return;
}
}
//Console.WriteLine(sb.ToString());
WriteStreamMethod(string.Format("d:\\Document{0}.txt", fileCount), sb.ToString());
if (i % TotalCountInEveryFile == )
{
i--;
}
fileCount++;
}
}
}
#endregion public static List<string> GetStreamMethod(string path)
{
List<string> list = new List<string>();
StreamReader sr = new StreamReader(path);
String line;
while ((line = sr.ReadLine()) != null)
{
list.Add(line.ToString());
}
return list;
} public static string GetStrMethod(string path)
{
StringBuilder list = new StringBuilder();
StreamReader sr = new StreamReader(path);
String line;
while ((line = sr.ReadLine()) != null)
{
list.Append(line.ToString());
}
return list.ToString();
} public static void WriteStreamMethod(string path, string content)
{
FileStream fs = new FileStream(path, FileMode.Create);
StreamWriter sw = new StreamWriter(fs);
sw.Write(content);
sw.Flush();
sw.Close();
fs.Close();
} public static string GetCustomNo()
{
var filePath = "D:\\cus.txt";
string gotStrings = GetStrMethod(filePath);
var jsonParse = gotStrings.ToString();
//JObject JsonObj = JObject.Parse(jsonParse);
JArray list = JArray.Parse(jsonParse);
IList<JToken> delList = new List<JToken>();
List<string> tempStr = new List<string>();
StringBuilder s = new StringBuilder();
foreach (var ss in list) //查找某个字段与值
{
if (((JObject)ss)["CustosNo"].ToString() != "aa")
//tempStr.Add(((JObject)ss)["CustosNo"].ToString());
s.Append("'"+((JObject)ss)["CustosNo"].ToString()+"',");
//delList.Add(ss);
} //var purchaseInfoes = JsonConvert.DeserializeObject<string>(JsonObj["CustosNo"].ToString());
return s.ToString().TrimEnd(','); }
}
}

文件实现