--导数据 Merge
MERGE os_staff AS t USING (select ear_code,sta_code,sta_pwd,sta_name,sta_dpt_code,job_code,sta_join_date,sta_sex,sta_status from ITSV123.his000.dbo.os_staff) AS s ON (t.ear_code = s.ear_code and t.sta_code = s.sta_code and t.sta_name != s.sta_name) WHEN MATCHED THEN update set t.sta_name = s.sta_name; WHEN NOT MATCHED THEN insert values(s.ear_code,s.sta_code,s.sta_pwd,s.sta_name,s.sta_dpt_code,s.job_code,s.sta_join_date,s.sta_sex,s.sta_status)
--查询数据库端口号 exec sys.sp_readerrorlog 0, 1, 'listening'
--批处理执行SQL @ECHO OFF SET dbhost=主机名(例如:127.0.0.1) SET dbuser=用户名(例如:sa) SET dbpasswd=用户密码(例如:admin) set dbName=数据库名称(例如:test) SET sqlpath=%~dp0(此语句可以保证.bat同级目录下的.sql文件能被找到) set sqlfile=update.sql(需要执行执行sql的文件) ::执行SQL脚本 osql -S %dbhost% -U %dbuser% -P %dbpasswd% -d %dbName% -i %sqlpath%%sqlfile% ECHO 完成! PAUSE @ECHO Done!