如何使用SQL命令在C#中实现此计划?

时间:2015-08-08 06:42:24

标签: c# sql-server

我有两张桌子:

  • 表1列name_markaz nvarchar(100)code_markaz nchar(20);
  • 表2列name_markaz nvarchar(100)code_markaz nchar(20);

我想实现这个计划,从表1中读取所有数据,并在这个条件下插入表2:

if table1.code_markaz not found in table 2.code_markaz then

   insert the table1.code_markaz into the table2.code_markaz

1 个答案:

答案 0 :(得分:1)

我认为这个查询可以做到(我更喜欢使用INSERT INTO table2 (name_markaz, code_markaz) SELECT name_markaz, code_markaz FROM table1 WHERE NOT EXISTS (SELECT 1 FROM table2 ti WHERE ti.code_markaz = table1.code_markaz); ):

var route:[PFObject] = [PFObject]()


override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {


  if segue == "toRoutesDetailVC" {


if let indexPath = self.tableView?.indexPathForSelectedRow()?.row {

let nav = segue.destinationViewController as! PoolRouteDetailVC

  var objects = self.route[indexPath] as! PFObject


nav.currentObjects = [objects]