C# SQL代码字符拼接

  1. 前提名命空间:using System.Text;
  2. StringBuilder Builder = newStringBuilder();//字符串拼接
  3. Builder.AppendLine("Declare @fk_guid int set @fk_guid='" + fk_guid + "'");
  4. //查申请数
  5. Builder.AppendLine("select Guid,a1 MaterialGuid,case when a3 is null then a2 else a3 end Amount into #TT from T_WuPinShenQing_01 where 
  6. fk_guid=@fk_guid");
  7. //清除已前的占料数据
  8. Builder.AppendLine("Delete T_WuPinShenQing_03 where fk_guid=@fk_guid and Status=2");
  9. Builder.AppendLine("Drop Table #TT");
  10. Console.WriteLine(Builder.ToString());
  11. Builder拼结输出结果:
  12. Declare @fk_guid int set @fk_guid='" + fk_guid + "'
  13. select Guid,a1 MaterialGuid,case when a3 is null then a2 else a3 end Amount into #TT from T_WuPinShenQing_01 where fk_guid=@fk_guid
  14. Delete T_WuPinShenQing_03 where fk_guid=@fk_guid and Status=2
  15. Drop Table #TT

你可能感兴趣的:(c#,sql,数据库)