问题描述
我想将多行列定义读入一行。
Create or replace view productsview
AS
SELECT
CAST('PS' AS VARCHAR(30)) + CAST(o.Process_id AS VARCHAR(4)) + '^' +
CAST(o.process_startid AS VARCHAR(3)) AS ProcessId,CAST('o.Product_name' AS VARCHAR(30)) + CAST(o.Proc_name AS VARCHAR(3)) AS ProductName,CAST(o.product_type AS VARCHAR(4)) AS productType,CAST(o.Process_start AS VARCHAR(3))+ CAST(o.process_end AS VARCHAR(3)) AS processperiod,CAST(o.LastmodifiedDate) AS LastmodifiedDate
列定义ProcessId
继续到第二行。我想在一行中读取它,因为我的程序旨在在一行中读取每个列定义。
CAST('PS' AS VARCHAR(30)) + CAST(o.Process_id AS VARCHAR(4)) + '^' + CAST(o.process_startid AS VARCHAR(3)) AS ProcessId,CAST(o.LastmodifiedDate) AS LastmodifiedDate
string connectionString,query;
var coltab = new List<ColumnInfo>();
var lsql = new List<String>();
var tlist = new List<String>();
foreach (string cur in tlist)
{
query = @"SELECT c.[obj_id],c.[cname],c.col_id
FROM sys.columns c
JOIN sys.views v
ON c.object_id = v.object_id
where v.name LIKE '%productsview%'";
using (sqlConnection connection = new sqlConnection(connectionString))
{
sqlCommand command = new sqlCommand(query,connection);
connection.open();
sqlDataReader reader = command.ExecuteReader();
try
{
while (reader.Read())
coltab.Add(new ColumnInfo { obj_id = reader.GetInt32(0),cname = reader.GetString(1),colid = reader.GetInt32(2) });
}
finally
{
reader.Close();
connection.Close();
}
}
query = @"DECLARE
@olddelim nvarchar(32) = char(13) + Char(10),@newdelim nchar(1) = NCHAR(9999);
SELECT * FROM STRING_SPLIT(REPLACE(OBJECT_DEFinitioN(obj_id('productsview')),@olddelim,@newdelim),@newdelim);";
using (sqlConnection connection = new sqlConnection(connectionString))
{
sqlCommand command = new sqlCommand(query,connection);
connection.open();
sqlDataReader reader = command.ExecuteReader();
try
{
while (reader.Read())
lsql.Add(reader.GetString(0));
}
finally
{
reader.Close();
connection.Close();
}
}
foreach (ColumnInfo column in coltab)
{
int ln = 0;
foreach (string sline in lsql)
{
int cm = -1;
cm = sline.IndexOf(column.cname);
if (cm > -1)
{
int im = 0;
foreach (ColumnInfo colsearch in coltab)
if (colsearch.cname.Contains(lsql[ln - 1]))
{
im = im + 1;
break;
}
else
im = 0;
}
if (im >= 1)
{
System.Console.WriteLine("do not combine");
}
else
{
string sr = lsql[ln - 1];
string sr1 = sr + sline;
System.Console.WriteLine(sr1);
}
}
ln = ln + 1;
}
}
问题出在循环的else
部分。
else
{
string sr = lsql[ln - 1];
string sr1 = sr + sline;
System.Console.WriteLine(sr1);
}
有没有办法获得正确的输出?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)