sql語句多條件簡單寫法
阿新 • • 發佈:2017-09-07
inner 寫法 color clas alt ren .cn log !=
比如用戶可以按姓名跟添加時間任意情況搜索
拼接sql語句可以這樣寫
string sql1 = @"SELECT dbo.RenYuan.Name, dbo.BiYeLunWenKeTi.KeTiMing, dbo.BiYeLunWenKeTi.KeTiNeiRong, dbo.BiYeLunWenKeTi.KeTiId, dbo.BiYeLunWenKeTi.UserId, dbo.BiYeLunWenKeTi.BianJiShiJian, dbo.BiYeLunWenKeTi.Remark, dbo.BiYeLunWenKeTi.Stop, dbo.BiYeLunWenKeTi.XuanTiRenShu, RenYuan_1.Name AS BianJiRen, dbo.BiYeLunWenKeTi.YunXuRenShu, dbo.NianJi.NianJiName, dbo.KeTiNianJi.NianJiId, dbo.BiYeLunWenKeTi.TianJiaShiJian, dbo.JiaoShi.JiaoShiId FROM dbo.NianJi INNER JOIN dbo.KeTiNianJi ON dbo.NianJi.NianJiId = dbo.KeTiNianJi.NianJiId RIGHT OUTER JOIN dbo.JiaoShi INNER JOIN dbo.RenYuan ON dbo.JiaoShi.RenYuanId = dbo.RenYuan.RenYuanId INNER JOIN dbo.BiYeLunWenKeTi ON dbo.JiaoShi.JiaoShiId = dbo.BiYeLunWenKeTi.DaoShiId INNER JOIN dbo.RenYuan AS RenYuan_1 ON dbo.BiYeLunWenKeTi.UserId = RenYuan_1.RenYuanId ON dbo.KeTiNianJi.KeTiId = dbo.BiYeLunWenKeTi.KeTiId WHERE 1=1"; if (RenYuanId != "") { sql1 = sql1 + "and dbo.RenYuan.RenYuanId=‘" + RenYuanId + "‘ "; } if(txtTianJiaShiJian.Text!="") { sql1 = sql1 + " and dbo.BiYeLunWenKeTi.TianJiaShiJian=‘" + txtTianJiaShiJian.Text + "‘"; }
sql語句多條件簡單寫法