C#中 SQL语句

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语句

基础教程推荐