cstring format 哪里有错误?

starsky_1 2008-12-12 09:18:13
sql.Format ("SET NOCOUNT ON declare @num int set @num=0 select 线路号, 站点名, 路线=cast('('+线路号+':'+站点名 as varchar(4000)), 序号=序号, tt=@num into # from 线路站点 where 站点名='%s'; while @@rowcount>0 and not exists (select * from # where 站点名='%s') begin set @num=@num+1 insert into #(路线,线路号,站点名,序号,tt) select 路线=a.路线+case when a.线路号=b.线路号 then '->'+b.站点名 else ')转('+b.线路号+':'+b.站点名 end, b.线路号,b.站点名,b.序号,@num from # a, 线路站点 b where a.tt=@num-1 and(a.站点名=b.站点名 and a.线路号<>b.线路号 or a.线路号=b.线路号 and (a.序号=b.序号+1 or a.序号=b.序号-1)) and len(a.路线)<4000 and patindex('%[ >]'+b.站点名+'[-)]%',a.路线)=0 end select '路线'=路线+')' from # where tt=@num and 站点名='%s' if @@rowcount =0 select * from # ;drop table #;",station_start,station_end,station_end);

比较长了点 但不是错误吧?
那到底哪里出错了?
...全文
84 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
ljhcy99 2008-12-12
  • 打赏
  • 举报
回复
sql.Format ("SET NOCOUNT ON declare @num int set @num=0
select 线路号, 站点名, 路线=cast('('+线路号+':'+站点名 as varchar(4000)),
序号=序号, tt=@num
into #
from 线路站点
where 站点名='%s';
while @@rowcount>0 and not exists (select * from # where 站点名='%s')
begin
set @num=@num+1
//
这一行应该有错误,你的#临时表的结构应该是(线路号, 站点名, 路线,序号,TT),
//
insert into #(路线,线路号,站点名,序号,tt)

select 路线=a.路线+case when a.线路号=b.线路号 then '->'+b.站点名 else ')转('+b.线路号+':'+b.站点名 end,
b.线路号,b.站点名,b.序号,@num
from # a, 线路站点 b
where a.tt=@num-1
and(a.站点名=b.站点名 and a.线路号 <>b.线路号 or a.线路号=b.线路号
and (a.序号=b.序号+1 or a.序号=b.序号-1))
and len(a.路线) <4000
and patindex('%[ >]'+b.站点名+'[-)]%',a.路线)=0
end
select '路线'=路线+')' from #
where tt=@num
and 站点名='%s'
if @@rowcount =0
select * from # ;
drop table #;"
,station_start,station_end,station_end);
starsky_1 2008-12-12
  • 打赏
  • 举报
回复
up
【前言】 工作或学习中可能需要实现基于VC读\写Excel文件的功能,本人最近也遇到了该问题。中间虽经波折,但是最终还是找到了解决问题的办法。 在此跟大家分享,希望对跟我同样迷茫过的同学们有所帮助。 1、程序功能 1)打开一个excel文件; 2)显示到CListCtrl上; 3)新建一个Excel文件。 以上均在对话框中实现。 2、平台 VC++2010 3、实现方法 常用的Excel打开方式有两种 1)通过数据库打开; 2)OLE方式打开。 由于方式1)操作繁琐,经常出现莫名的错误,这里选用方式2). 4、准备步骤 首先新建一个Dialog窗体程序,添加list control和两个按钮 1)将ExcelLib文件夹拷贝到程序目录下; 2)将Export2Excel.h,Export2Excel.cpp两个文件添加到项目; 3)包含头文件,#include "ExcelLib/Export2Excel.h" 通过以上步骤在程序中引入了可以读取Excle文件的CExport2Excel类; 5、打开excel文件 通过按钮点击打开 void CExcelTestDlg::OnBnClickedButtonOpenExcel() { //获取文件路径 CFileDialog* lpszOpenFile; CString szGetName; lpszOpenFile = new CFileDialog(TRUE,"","",OFN_FILEMUSTEXIST|OFN_HIDEREADONLY,"Excel File(*.xlsx;*.xls)|*.xls;*.xlsx",NULL); if (lpszOpenFile->DoModal()==IDOK) { szGetName = lpszOpenFile->GetPathName(); SetWindowText(szGetName); delete lpszOpenFile; } else return; //打开文件 //文件中包含多个sheet时,默认打开第一个sheet CExport2Excel Excel_example; Excel_example.OpenExcel(szGetName); //获取sheet个数 int iSheetNum = Excel_example.GetSheetsNumber(); //获取已使用表格行列数 int iRows = Excel_example.GetRowCount(); int iCols = Excel_example.GetColCount(); //获取单元格的内容 CString cs_temp = Excel_example.GetText(1,1); //AfxMessageBox(cs_temp); //List control上显示 //获取工作表列名(第一行) CStringArray m_HeadName; m_HeadName.Add(_T("ID")); for (int i=1;iGetItemCount()>0) { m_list.DeleteColumn(0); } //初始化ClistCtrl,加入列名 InitList(m_list,m_HeadName); //填入内容 //第一行是标题,所以从第2行开始 CString num; int pos; for (int row = 2;row<=iRows; row++) { pos = m_list.GetItemCount(); num.Format(_T("%d"),pos +1); m_list.InsertItem(pos,num); for (int colum=1;columDoModal()==IDOK) { szGetName = lpszOpenFile->GetPathName(); SetWindowText(szGetName); delete lpszOpenFile; } else return; //文件全名称 CString csFileName = szGetName; //需要添加的两个sheet的名称 CString csSheetName = "newSheet"; CString csSheetName2 = "newSheet2"; // 新建一个excel文件,自己写入文字 CExport2Excel Excel_example; //新建excel文件 Excel_example.CreateExcel(csFileName); //添加sheet,新加的sheet在前,也就是序号为1 Excel_example.CreateSheet(csSheetName); Excel_example.CreateSheet(csSheetName2); //操作最开始添加的sheet:(newSheet) Excel_example.SetSheet(2); //添加表头 Excel_example.WriteHeader(1,"第一列"); Excel_example.WriteHeader(2,"第二列"); //添加核心数据 Excel_example.WriteData(1,1,"数据1"); Excel_example.WriteData(1,2,"数据2"); //保存文件 Excel_example.Save(); //关闭文件 Excel_example.Close(); } 7、注意事项 1)一般单个Excel文件包含多个sheet,程序默认打开第一个; 2)指定操作sheet,使用Excel_example.SetSheet(2)函数; 3)打开文件时最左侧的sheet序号为1,新建excel时最新添加的sheet序号为1. 【后记】 本程序主要基于网络CSDN中---“Excel封装库V2.0”---完成,下载地址是:http://download.csdn.net/detail/yeah2000/3576494,在此表示感谢!同时, 1)在其基础上作了小改动,改正了几个小错误,添加了几个小接口; 2)添加了如何使用的例子,原程序是没有的; 3)详细的注释 发现不足之处,还请大家多多指教!

34,575

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧