Note that there are some explanatory texts on larger screens.

plurals
  1. POCase query is not working
    primarykey
    data
    text
    <p>New to SQL and any help would be welcomed.</p> <p>Can anyone advise on the best approach for the creating the following query.</p> <pre><code> _hs_eb_code1 = 'bf', then set format = _hs_eb_det1 _hs_eb_code# = 'bf', then set format = _hs_eb_det# Repeat until _hs_eb_code# (1-9), </code></pre> <p>However if the character length of <code>_hs_eb_det1</code> exceeds 100 characters, then prefix with <code>'*'</code>. In addition _hs_eb_code1 = 'bf' is one, while _hs_eb_det1 will provide many in terms of results.</p> <p>So far, I can use case query to check for the first part, then build another query. I get lost.</p> <p>The query:</p> <pre><code> SELECT CASE WHEN LEN(FORMAT) &lt; 100 THEN LEFT(FORMAT,100) ELSE '*'+FORMAT END AS FORMAT FROM (SELECT CASE WHEN EXISTS (SELECT _HS_EB_CODE1 FROM DBO.SRC_HBL_CLNT_CAT WHERE _HS_EB_CODE1 = 'BF') THEN _HS_EB_DET1 WHEN EXISTS (SELECT _HS_EB_CODE2 FROM DBO.SRC_HBL_CLNT_CAT WHERE _HS_EB_CODE2 = 'BF') THEN _HS_EB_DET2 WHEN EXISTS (SELECT _HS_EB_CODE3 FROM DBO.SRC_HBL_CLNT_CAT WHERE _HS_EB_CODE3 = 'BF') THEN _HS_EB_DET3 WHEN EXISTS (SELECT _HS_EB_CODE4 FROM DBO.SRC_HBL_CLNT_CAT WHERE _HS_EB_CODE4 = 'BF') THEN _HS_EB_DET4 WHEN EXISTS (SELECT _HS_EB_CODE5 FROM DBO.SRC_HBL_CLNT_CAT WHERE _HS_EB_CODE5 = 'BF') THEN _HS_EB_DET5 WHEN EXISTS (SELECT _HS_EB_CODE6 FROM DBO.SRC_HBL_CLNT_CAT WHERE _HS_EB_CODE6 = 'BF') THEN _HS_EB_DET6 WHEN EXISTS (SELECT _HS_EB_CODE7 FROM DBO.SRC_HBL_CLNT_CAT WHERE _HS_EB_CODE7 = 'BF') THEN _HS_EB_DET7 WHEN EXISTS (SELECT _HS_EB_CODE8 FROM DBO.SRC_HBL_CLNT_CAT WHERE _HS_EB_CODE8 = 'BF') THEN _HS_EB_DET8 WHEN EXISTS (SELECT _HS_EB_CODE9 FROM DBO.SRC_HBL_CLNT_CAT WHERE _HS_EB_CODE9 = 'BF') THEN _HS_EB_DET9 END ) AS FORMAT FROM DBO.SRC_TBM_BILLGRP </code></pre> <p>But I have a problem in that the query has one to many, therefore fails to work. WHEN EXISTS (SELECT _HS_EB_CODE1 FROM DBO.SRC_HBL_CLNT_CAT WHERE _HS_EB_CODE1 = 'BF') THEN _HS_EB_DET1 </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload