如何为DB2

时间:2016-03-04 19:16:08

标签: sql db2

如果Client为空,我需要更新address_1表中的所有记录,但address_2不是。address_2。在这些情况下,我想将address_1移至UPDATE Client SET Address_1 = 'address1', address_2 = '' WHERE client_id = 'client_id' 。这是我到目前为止的查询:

client_id

但我没有传递package com.example.administrador.app3; import android.Manifest; import android.app.ProgressDialog; import android.content.Intent; import android.content.pm.PackageManager; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.AsyncTask; import android.os.Build; import android.provider.Settings; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.TextView; import android.widget.Toast; import java.io.File; import java.util.HashMap; public class MainActivity extends AppCompatActivity { private TextView textView; private LocationManager locationManager; private LocationListener locationListener; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); textView = (TextView) findViewById(R.id.textView); locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); locationListener = new LocationListener() { @Override public void onLocationChanged(Location location) { //textView double latit = location.getLatitude(); double longit = location.getLongitude(); final String lat = String.valueOf(latit); final String lng = String.valueOf(longit); class AddCoord extends AsyncTask<Void,Void,String>{ ProgressDialog loading; @Override protected void onPreExecute(){ super.onPreExecute(); loading = ProgressDialog.show(MainActivity.this,"Adding...","Wait...",false,false); } @Override protected void onPostExecute(String s) { super.onPostExecute(s); loading.dismiss(); Toast.makeText(MainActivity.this, s, Toast.LENGTH_LONG).show(); } @Override protected String doInBackground(Void... v) { HashMap<String,String> params = new HashMap<>(); params.put(Config.KEY_EMP_LAT,lat); params.put(Config.KEY_EMP_LNG,lng); RequestHandler rh = new RequestHandler(); String res = rh.sendPostRequest(Config.URL_ADD, params); return res; } } AddCoord ac = new AddCoord(); ac.execute(); } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(intent); } }; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { requestPermissions(new String[]{ Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.INTERNET }, 10 ); return; } }else{ locationManager.requestLocationUpdates("gps", 300000, 0, locationListener); } } @Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { switch (requestCode){ case 10: if(grantResults.length>0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) locationManager.requestLocationUpdates("gps", 300000, 0, locationListener); } } } ,而是想更新每条记录。

1 个答案:

答案 0 :(得分:1)

您需要的查询是

UPDATE client SET address_1 = address_2, address_2 = ''
WHERE address_1 = '' AND address_2 != ''

WHERE中,它会找到所有问题行,然后将address_2移至address_1并清空address_2

注意:确保您不会将空字符串''NULL混淆。在DB2中,那些不一样。如果您的值实际为NULL,则您的查询必须为:

UPDATE client SET address_1 = address_2, address_2 = NULL
WHERE address_1 IS NULL AND address_2 IS NOT NULL