[英]How to set column value in SQL select statement?
I want to set one column value in all rows to "0" 我想将所有行中的一列值设置为“ 0”
SqlCommand cmd = m_objDbCAPEX.GetSqlCommand(CommandType.Text);
cmd.CommandText = "SELECT CAPEX_BillOfMaterialItem.* FROM CAPEX_BillOfMaterialItem,CAPEX_BillOfMaterial WHERE CAPEX_BillOfMaterialItem.szBillOfMaterialId = CAPEX_BillOfMaterial.szBillOfMaterialId and CAPEX_BillOfMaterial.szProjectCode = '" + szProjectCode + "'";
da = new SqlDataAdapter(cmd);
da.Fill(dtDat);
You can try to set it like this: 您可以尝试这样设置:
select 0 as fieldName, col1, col2,... from yourTable
In this case your fieldName
column will be set as 0. ( You can replace the actual name of the column with fieldName ) 在这种情况下,您的
fieldName
列将设置为0。( 您可以使用fieldName替换列的实际名称 )
Adding a point to @Rahul's answer. 在@Rahul的答案上加点。
If the field has specific values and if you want that alone to make it to 0 then you need CASE statements. 如果该字段具有特定值,并且如果您只想将其设为0,则需要CASE语句。
SELECT CASE
WHEN capex_billofmaterialitem.fieldname = 'checking value goes here'
THEN 0
ELSE capex_billofmaterialitem.fieldname
END AS fieldname1,
capex_billofmaterialitem.*
FROM capex_billofmaterialitem,
capex_billofmaterial
WHERE capex_billofmaterialitem.szbillofmaterialid =
capex_billofmaterial.szbillofmaterialid
AND capex_billofmaterial.szprojectcode = '" + szProjectCode + "'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.