我有一个SQL查询,它从SQLdatabase中检索信息,我需要为我发送给客户端的每个批次添加一个头文件和预告片。我搜索过但不是运气。标题记录应该有Recordtype(1)CPC编号(0000)文件序列号(001)和预告片记录应该有记录类型(1)请求总数(5),总法院费用(),索赔总额()。
string stringSql1 = " SELECT distinct " +
"'" + comboBox6.Text + "' as Recordtype" +
",'" + textBox5.Text + "' as Recordtype" +
" , space(1983) ";
string stringSql = " SELECT distinct " +
"'" + comboBox6.Text + "' as RecordType" +
" , left([Claimant Name] +' ',30) " +
" , left([Claimant Address1] +' ',30) " +
" , left([Claimant Address2] +' ',30) as ClaimantAddress2 " +
" , left([Claimant Address3] +' ',30) as ClaimantAddress3 " +
" , left([Claimant Address4] +' ',30) as ClaimantAddress4 " +
string whereClause = "";
===so on ....==================================
string[] tempArray = new string[this.txt.Lines.Length];
tempArray = this.txt.Lines;
if (this.txt.Lines.Length == 0)
{
return;
}
for (int counter = 0; counter <= tempArray.Length-1; counter++)
{
if (tempArray[counter].Trim().Length > 0)
{
whereClause = whereClause + "'" + tempArray[counter] + "'" + ", ";
}
}
whereClause = whereClause.TrimEnd(' ', ',');
whereClause = "(" + whereClause + ")";
stringSql = stringSql.Replace("{where}", whereClause);
myDataset = new DataSet("SQL");
SqlConnection myConn = new SqlConnection();
SqlCommand myCommand = new SqlCommand();
myCommand.CommandType = CommandType.Text;
myCommand.CommandText = stringSql;
myCommand.Connection = myConn;
SqlDataAdapter myAdapter = new SqlDataAdapter();
myAdapter.SelectCommand = myCommand;
myAdapter.Fill(myDataset);
答案 0 :(得分:0)
假设您希望在单个SELECT
语句中完成所有这些操作,您可以添加包含汇总信息(如总计,统计信息和内容)的列到典型的SELECT
。 E.G。
declare @sumTotal decimal
set @sumTotal = (SELECT SUM(ColumnName) FROM tableNameY)
--declare similar variables for total number of request(5), total court fee() and total claim amount().
--Create a query that outputs row data along with the info you just calculated
select '0000' as 'CPC number', '001' as 'File sequence number', ColumnName, @sumTotal as 'total number of request', @totalCourtFeesvariable as 'total court fees'--etc...
from tableNameX