永发信息网

sql server 怎样将字符串拼接的方法

答案:2  悬赏:50  手机版
解决时间 2021-03-07 03:23
  • 提问者网友:咪咪
  • 2021-03-07 00:13
sql server 怎样将字符串拼接的方法
最佳答案
  • 五星知识达人网友:独行浪子会拥风
  • 2021-03-07 01:32
String ProductionProduct = temp.Rows[i][3].ToString().Trim();
//StringBuilder Sql2 = new StringBuilder();
//Sql2.Append("select top 1 [ProductID] from [Product] where [productname] =");
//Sql2.Append("N'" + ProductionProduct + "';");
//String sql22 = Sql2.ToString();
String sql2 = @"select [ProductID] from [Product] where [productname] =N'"+ ProductionProduct+ "'";
List< ProductModel > res2 = db.Database.SqlQuery<ProductModel >(sql2).ToList();
string ProductID = string.Empty;
foreach ( ProductModel productname in res2)
{
ProductID = String.Format( "{0}" , productname.ProductID);
}
将数据库中字段为空的赋值为0
update Material set MaterialTypeID='0' where MaterialTypeID='' or MaterialTypeID is NULL!
全部回答
  • 1楼网友:鱼芗
  • 2021-03-07 02:36
你的问题,问的不是很清楚,你是想问,如果将查询结果拼接为字符串吗? 有两种办法,如果是拼接为一个字符串,可以用变量,如: declare @names varchar(max) select @names=isnull(@names+',','')+t.name from sys.tables as t select @names --返回:spt_fallback_db,spt_fallback_dev,spt_fallback_usg,spt_monitor,msreplication_options如果是用sql中,可以用xml path如: select stuff( (select ','+t.name from sys.tables as t for xml path('')) ,1,1,'') --返回spt_fallback_db,spt_fallback_dev,spt_fallback_usg,spt_monitor,msreplication_options
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯