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


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(','); }
}
}
文件实现
SQL查询条件生成小工具的更多相关文章
- spring MVC +freemarker + easyui 实现sql查询和执行小工具总结
项目中,有时候线下不能方便的连接项目中的数据源时刻,大部分的问题定位和处理都会存在难度,有时候,一个小工具就能实时的查询和执行当前对应的数据源的库.下面,就本人在项目中实际开发使用的小工具,实时的介绍 ...
- JavaGUI练习 - 正交测试用例生成小工具
正交表生成小工具 说明 小工具的适用对象主要是测试人员,他们日常工作中手动设计大量测试用例,工作繁杂甚至还存在覆盖不全面等问题. 为了提高他们的测试效率,该小工具可以通过输入一组多因素多水平的数据,然 ...
- SQL转Java代码小工具
工作中使用SQL的时候很多,当使用hibernate的时候,经常遇到多行的SQL,通常在PL/SQL或其他地方写好SQL,测试没问题后,需要将SQL写到程序代码中,多行SQL需要拼接字符串,手动一行行 ...
- PyQt5-GUI生成随机生成小工具
自己修改了代码:实现了自动生成SSN,手机号和姓名的功能 import sys from PyQt5.QtGui import * from PyQt5.QtWidgets import * from ...
- 论Top与ROW_NUMBER读取第一页的效率问题及拼接sql查询条件
http://www.cnblogs.com/Leo_wl/p/4921799.html SELECT TOP * FROM users WHERE nID> And nID< ORDER ...
- 后端根据查询条件生成excel文件返回给前端,vue进行下载
一.HTML代码 <el-col :xs="2" :md="2" :sm="3"> <el-button type=&qu ...
- SQL 查询条件放在LEFT OUTER JOIN 的ON语句后与放在WHERE中的区别
这两种条件放置的位置不同很容易让人造成混淆,以致经常查询出莫名其妙的结果出来,特别是副本的条件与主表不匹配时,下面以A,B表为例简单说下我的理解. 首先要明白的是: 跟在ON 后面的条件是对参与左联接 ...
- sql查询条件为空的另类写法o( ̄▽ ̄)d
简单描述:今天看老大提交的代码,发现了一个有意思的事情,一条sql中判断条件是空,老大的写法,让我眼前一亮.直接上代码 代码: <select id="getxxxs" re ...
- 查询expression的小工具
今天在研究flipsolve的时候无意间写了个shelf tool,用于查询一大推节点中某些parameter的expression中是否存在我需要的关键字.就是简单的对所框选的节点进行一个循序查询参 ...
随机推荐
- Python之基本的日期与时间转换 datetime、 dateutil模块
简单举例datetime模块 from datetime import timedelta,datetime a = timedelta(days=2, hours=6) b = timedelta( ...
- 转:谈谈Linux下动态库查找路径的问题
http://blog.chinaunix.net/uid-23069658-id-4028681.html 学习到了一个阶段之后,就需要不断的总结.沉淀.清零,然后才能继续“上路”.回想起自己当年刚 ...
- 最长上升子序列(LIS)长度及其数量
例题51Nod-1376,一个经典问题,给出一个序列问该序列的LIS以及LIS的数量. 这里我学习了两种解法,思路和代码都是参考这两位大佬的: https://www.cnblogs.com/reve ...
- js判断元素是否可见
dom元素是否可见可使用jq的is方法和dom的offsetParent === null方法 jq中 $(element).is(":visible") === true !!( ...
- 【CSS3】transform-origin以原点进行旋转 (转)
话不多说, 以左上角为原点 -moz-transform-origin: 0 0; -webkit-transform-origin:0 0; -o-transform-origin:0 0; 以右上 ...
- java--substring内存溢出问题
public class SubStringDemo { //substring() /** * jdk6 当调用 substring() 方法时,创建了一个新的String对象,但是string的v ...
- 【leetcode】989. Add to Array-Form of Integer
题目如下: For a non-negative integer X, the array-form of X is an array of its digits in left to right o ...
- 【leetcode】988. Smallest String Starting From Leaf
题目如下: Given the root of a binary tree, each node has a value from 0 to 25representing the letters 'a ...
- 【基础】Maven生命周期
Maven是一个优秀的项目管理工具,它能够帮你管理编译.报告.文档等. Maven的生命周期: maven的生命周期是抽象的,它本身并不做任何的工作.实际的工作都交由"插件"来完成 ...
- hdu 4826 Labyrinth(简单dp)
Description 度度熊是一只喜欢探险的熊,一次偶然落进了一个m*n矩阵的迷宫,该迷宫只能从矩阵左上角第一个方格开始走,只有走到右上角的第一个格子才算走出迷宫,每一次只能走一格,且只能向上向下向 ...