SQL语句SELECTSTUFF(((SELECT ,{+StructType:+CONVERT(VARCHAR(1),ISNULL(hb.StructType,0))+,IsCert:+CONVERT(VARCHAR(1),ISNULL(hb.IsCert,0))+,Area:+CONVERT(VARCHAR(18),ISNULL(hb.Area,0))+}FRO...
SQL语句
SELECT STUFF(( (SELECT ',{' +'"StructType":'+CONVERT(VARCHAR(1),ISNULL(hb.StructType,0)) +',"IsCert":'+CONVERT(VARCHAR(1),ISNULL(hb.IsCert,0)) +',"Area":'+CONVERT(VARCHAR(18),ISNULL(hb.Area,0)) +'}' FROM ZSJTTD_HouseBuilding hb WHERE hb.HouseID=h.ID AND hb.IsDeleted=0 FOR XML PATH(''))),1,1,'' ) HouseBuildingInfo, h.landPropertyOwner,h.CountAll, hh.Holder,hh.HolderIDcard, prj.landAssessPrice,prj.settlementCostPrice,prj.settlementPrice,prj.startSignDate,prj.NonHOuseSignAwardJSON,prj.NonHouseEmptyAwardJSON FROM ZSJTTD_House h LEFT JOIN ZSJTTD_HouseHolder hh ON hh.id=h.holderID LEFT JOIN ZSJTTD_Project prj ON prj.ID=h.PrjID WHERE h.id='a83d70fa-0952-46aa-bd1d-2e5adca4c0b2'
C#接口中:(转义字符的使用)
string xml = string.Format(@"STUFF (((SELECT ',{{'+'""StructType"":'+CONVERT(VARCHAR(1),ISNULL(hb.StructType,0))" +@"+ ',""IsCert"":' + CONVERT(VARCHAR(1), ISNULL(hb.IsCert, 0))" +@"+ ',""Area"":' + CONVERT(VARCHAR(18), ISNULL(hb.Area, 0))" +"+'}}' " +@" FROM ZSJTTD_HouseBuilding hb WHERE hb.HouseID = h.ID AND hb.IsDeleted = 0 FOR XML PATH(''))),1,1,'' ) HouseBuildingInfo");
string sql = string.Format(@"SELECT {0}, h.landPropertyOwner,h.CountAll, hh.Holder,hh.HolderIDcard, prj.landAssessPrice,prj.settlementCostPrice,prj.settlementPrice,prj.startSignDate,prj.NonHOuseSignAwardJSON,prj.NonHouseEmptyAwardJSON FROM ZSJTTD_House h LEFT JOIN ZSJTTD_HouseHolder hh ON hh.id = h.holderID LEFT JOIN ZSJTTD_Project prj ON prj.ID = h.PrjID WHERE h.id = '{1}'", xml, HouseId);
沃梦达教程
本文标题为:C#中 SQL语句
基础教程推荐
猜你喜欢
- 浅谈C# async await 死锁问题总结 2023-03-14
- unity实现延迟回调工具 2023-05-06
- Unity之绕轴进行旋转的操作 2023-04-10
- [随笔]Centos 7上部署.net core webapi 2023-09-26
- C#使用NPOI实现Excel导入导出功能 2023-05-22
- C#序列化与反序列化集合对象并进行版本控制 2023-07-04
- C#在Winform开发中使用Grid++报表 2023-01-16
- c# 委托的常见用法 2023-03-09
- C#多线程之线程同步 2023-05-26
- VS2010下生成dll的方法 2022-12-06