请教c# sql重复语句套接字符串
请教c# sql重复语句套接字符串
sql+=",(Case when a.Condition='1' and a.Grade='0' then Ceiling(Datediff(Minute,a.KaiTime,getdate())*b.sMoney/60) when a.Condition='1' and a.Grade>='1' then Ceiling(Datediff(Minute,a.KaiTime,getdate())*b.hMoney/60) End)As spMoney";//消费
c# 程序在sql查询中反复重复的字符串太麻烦了。有方法简化,使用字符串代入方法吗?
假如这样:
string sp="Ceiling(Datediff(Minute,a.KaiTime,getdate())*b.sMoney/60)";
sql+=",(Case when a.Condition='1' and a.Grade='0' then '"+sp+"' when a.Condition='1' and a.Grade>='1' then '"+sp+"' End)As spMoney";//消费
但是这样写提示错误,如果这个方法正确,可以节省好多重复的字符串。希望各位给出好方法。