案例何时检查是否为空

时间:2017-03-22 19:54:00

标签: mysql sql

我有一个针对报告的客户端的过滤器,如果该人使用它所使用的过滤器客户端,否则它会忽略并带来所有客户端。 这是我的Where子句。

Where [S].ano_mes = @ano_mes OR @ano_mes IS NULL    
            AND S.cnpj = @cnpj or @cnpj is null     
            AND S.cod_produto = @cod_produto or @cod_produto is null    
            AND CASE WHEN (len(@cnpj) > 0) THEN 
                 (S.CGC_Cliente +''-''+S.Seq_Cliente) in(SELECT cnpjseq FROM #Tb_CliSelecionados)
                    END

问题在于CASE WHEN部分,其余部分有效。

如果变量@cnpj的值为THEN,则应使用过滤器。

过滤器一起是CGC_CLIENTE和SEQ_CLIENTE。

表#TB_CliSelecionados的参数为Concatenated equals,例如,带有别名S的表和#Tb_CliSelecionados具有' 060746948041730-00'

我在" IN"它说" IN"附近的语法不正确 在END中说错误的语法接近" END" .Expection")"

有人知道在部分情况下我做错了什么?

3 个答案:

答案 0 :(得分:1)

public class PageFragment extends Fragment implements SortDialogCallback { private static final String TAG = PageFragment.class.getSimpleName(); /** * Unsplash API, By Default=10 */ private static final String per_page = "10"; public static String order_By; /** * Unsplash API call parameter, By Default=latest * Change it in Pager Fragment, based on Tab tapped */ RecyclerView recyclerView; ImageAdapter imageAdapter; GridLayoutManager layoutManager; EndlessRecyclerViewScrollListener scrollListener; FloatingActionButton actionButton; FrameLayout no_internet_container; Bundle savedInstanceState; // Attaching Handler to the main thread Handler handler = new Handler(); boolean shouldHandlerRunAgain = true; private ArrayList<DataModel> model; /** * Handler is attached to the Main Thread and it's message queue, because it is the one who created it. * <p> * Handler is responsible for checking every second that are we connected to internet, and if we are, then :- * 1. Then we remove empty view * 2. Make the network call * 3. Stop handler from posting the code again using shouldHandlerRunAgain variable * 3.1 This is a kill switch otherwise handler will post the runnable again and again to the message queue, which will be executed as soon as it reaches the looper * <p> * Handler removeCallbacks is used to remove all the pending runnables in the Message Queue */ Runnable job = new Runnable() { @Override public void run() { Log.d(TAG, "Thread run " + job.hashCode()); swapViews(); if (shouldHandlerRunAgain) handler.postDelayed(job, HANDLER_DELAY_TIME); } }; @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putString("ORDER_BY", order_By); } @Override public void onResume() { super.onResume(); if (handler != null) handler.post(job); } @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG, "Starting Handler"); layoutManager = new GridLayoutManager(getContext(), 2); scrollListener = new EndlessRecyclerViewScrollListener(layoutManager) { public void onLoadMore(int page, int totalItemsCount, RecyclerView view) { Log.w(TAG, "On load More Called with page number " + page); loadDataUsingVolley(page, order_By); } }; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.search: Toast.makeText(getContext(), "Async task", Toast.LENGTH_SHORT).show(); break; default: Toast.makeText(getContext(), "Invalid Options", Toast.LENGTH_SHORT).show(); } return true; } @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.menu_page_fragment, menu); } private void swapViews() { if (detectConnection(getContext()) == false) { recyclerView.setVisibility(View.INVISIBLE); actionButton.setVisibility(View.INVISIBLE); no_internet_container.setVisibility(View.VISIBLE); } else { Log.d(TAG, "Removing callbacks from handler and stopping it from posting"); shouldHandlerRunAgain = false; handler.removeCallbacks(job, null); handler = null; recyclerView.setVisibility(View.VISIBLE); actionButton.setVisibility(View.VISIBLE); no_internet_container.setVisibility(View.INVISIBLE); if (savedInstanceState != null) { loadDataUsingVolley(1, savedInstanceState.getString("ORDER_BY")); } else { order_By = "latest"; loadDataUsingVolley(1, order_By); } } } @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, final Bundle savedInstanceState) { this.savedInstanceState = savedInstanceState; View view = inflater.inflate(R.layout.fragment_page, container, false); actionButton = (FloatingActionButton) view.findViewById(R.id.sort_button); actionButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { SortDialog sortDialog = new SortDialog(); sortDialog.setTargetFragment(PageFragment.this, 911); sortDialog.show(getChildFragmentManager(), "sortfragment"); } }); recyclerView = (RecyclerView) view.findViewById(R.id.recyclerview); recyclerView.setHasFixedSize(true); no_internet_container = (FrameLayout) view.findViewById(R.id.no_internet_container); return view; } void setUpRecyclerView() { if (imageAdapter == null) imageAdapter = new ImageAdapter(getContext(), (model==null)?new ArrayList<DataModel>():model); recyclerView.setAdapter(imageAdapter); recyclerView.setLayoutManager(layoutManager); recyclerView.addOnScrollListener(scrollListener); } void loadDataUsingVolley(int page, String order_by) { final ProgressDialog dialog = ProgressDialog.show(getContext(), "Wallser", "Loading"); RequestQueue requestQueue = Volley.newRequestQueue(getContext()); String URL = "https://api.unsplash.com/photos/?page=" + page + "&client_id=" + api_key + "&per_page=" + per_page + "&order_by=" + order_by; Log.d(TAG, URL); JsonArrayRequest objectRequest = new JsonArrayRequest(Request.Method.GET, URL, null, new Response.Listener<JSONArray>() { @Override public void onResponse(JSONArray array) { int len = array.length(); if (model == null) model = new ArrayList<>(); for (int i = 0; i < len; i++) { try { JSONObject object = array.getJSONObject(i); String id = object.getString("id"); JSONObject object1 = object.getJSONObject("urls"); String imageURL = object1.getString("regular"); JSONObject object2 = object.getJSONObject("links"); String downloadURL = object2.getString("download"); model.add(new DataModel(imageURL, downloadURL, id)); Log.d(TAG, downloadURL); } catch (JSONException e) { e.printStackTrace(); } } if (dialog != null) { dialog.dismiss(); } Log.d(TAG, model.size() + ""); setUpRecyclerView(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { dialog.dismiss(); Toast.makeText(getContext(), "" + error.getMessage(), Toast.LENGTH_SHORT).show(); } }); requestQueue.add(objectRequest); } /** * marks a new network call to Unsplash API * Thus, set model array list to null, to start fresh. * as model is reset, ImageAdapter also needs to start fresh. * * @param order_by */ @Override public void onDialogFinish(String order_by) { model = null; imageAdapter=null; order_By = order_by; loadDataUsingVolley(1, order_By); } } 返回一个表达式不是流量控制。

CASE

答案 1 :(得分:1)

CASE WHEN子句不正确。它应该看起来像:

         AND CASE 
             WHEN @cnpj IS NULL
                 THEN 1
             WHEN (len(@cnpj) = 0) 
                 THEN 1
             WHEN (S.CGC_Cliente +''-''+S.Seq_Cliente) in (SELECT cnpjseq FROM #Tb_CliSelecionados
                 THEN 1
             ELSE 0
         END = 1

答案 2 :(得分:0)

您可以将该部分更改为

private void Form1_Load(object sender, EventArgs e)
{
    var t = new DataTable();
    var tc = t.Clone();
    t.Columns.Add("C1");
    t.Rows.Add("A");
    t.Rows.Add("B");
    t.Rows.Add("C");
    t.Rows.Add("D");
    t.Rows.Add("E");
    currentBS.PositionChanged += (x, y) =>
    {
        if (currentBS.Position == 0)
            previousBS.DataSource = tc;
        else
        {
            previousBS.DataSource = t;
            previousBS.Position = this.currentBS.Position - 1;
        }
        if (currentBS.Position == currentBS.Count - 1)
            nextBS.DataSource = tc;
        else
        {
            nextBS.DataSource = t;
            nextBS.Position = this.currentBS.Position + 1;
        }
    };
    previousBS.DataSource = tc;
    nextBS.DataSource = tc;
    currentBS.DataSource = t;
    this.previousTextBox.DataBindings.Add("Text", previousBS, "C1");
    this.currentTextBox.DataBindings.Add("Text", currentBS, "C1");
    this.nextTextBox.DataBindings.Add("Text", nextBS, "C1");
}