大家好,
I have a table which contains two type of Establishments:
如果SIRET为空 - >这是一个ENTREPRISE
如果SIRET不为空 - >这是一个etablishement
在我的表格中,我总是有这个词:如果SIRET为NULL,则表示SIREN不是NULL。
我想要的是在同一个COLUMNS中显示SIRET和SIREN,并按公司名称排序表(SIRET IF NOT NULL)或(如果不为空则SIREN)
这是我的疑问:
select CUSTOMER.CUSTOMER_ID, CUSTOMER.CUSTOMER_RCE_ID,
CUSTOMER.COMM_REGNUM_CUST,CUSTOMER.GROUP_CODE,
CUSTOMER.CUSTOMER_CORPORATE_NAME,
Replace(CUSTOMER.ADDRESS_COMPANY, '|', ', ') as ADDRESS_COMPANY,
CUSTOMER.COUNTRY_CODE, CUSTOMER.POST_CODE, CUSTOMER.CITY,
CUSTOMER.CUSTOMER_ATTRIBUTE1,CUSTOMER.CUSTOMER_ATTRIBUTE2,
CUSTOMER.CUSTOMER_ATTRIBUTE3, CUSTOMER.CUSTOMER_ATTRIBUTE4, CUSTOMER.CUSTOMER_ATTRIBUTE5, CUSTOMER.CREATED_DATE,
CUSTOMER.CREATED_BY,CUSTOMER.UPDATED_DATE, CUSTOMER.UPDATED_BY, CUSTOMER.TENANT_ID,
CUSTOMER.CUSTOMER_ACCOUNT, CUSTOMER.VAT_INTRA, CUSTOMER.VAT_SETTLEMENT,CUSTOMER.IS_HEADQUARTERS,
CUSTOMER.CUSTOMER_SAP_ID, CUSTOMER.ADDRESSGUID, CUSTOMER.SIREN_CORP as SIREN, CUSTOMER.COMMERCIAL_SEGMENT, CUSTOMER.CODE_NAF,
CUSTOMER.JUR_STATUS_COMP, CUSTOMER.SHARE_CAP_AMT,CUSTOMER.IS_ACTIVE_RCE, CUSTOMER.REGISTRATION_PLACE,STATUS.STATUS_NAME ,
CUSTOMER.RCE_ETAB_ID, REPLACE (CUSTOMER.COMM_REGNUM_CUST,' ','') AS SIRET from CUSTOMER
join CUSTOMER_STATUS on CUSTOMER_STATUS.CUSTOMER_STATUS_ID = (
select * from (select CUSTOMER_STATUS_ID from CUSTOMER_STATUS
where CUSTOMER.CUSTOMER_ID = CUSTOMER_STATUS.CUSTOMER_ID order by CUSTOMER_STATUS.UPDATED_DATE desc) CUSTOMER_STATUS where rownum = 1 )
join STATUS on CUSTOMER_STATUS.STATUS_ID = STATUS.STATUS_ID
我如何通过CUSTOMER.CUSTOMER_CORPORATE_NAME(公司或公司名称)和另一栏(SIRET或SIRET假设,如果其中一个是空的,而不是其他人)订购并将SIRET和SIREN置于同一列结果
提前离开你。
答案 0 :(得分:0)
部分解决方案可能是
SELECT
.
.
.
customer.customer_corporate_name,
isnull(customer.siren_corp
,Replace(customer.comm_regnum_cust, ' ', '')) AS SiretSiren
.
.
.
FROM customer
JOIN customer_status
.
.
.
ON customer_status.status_id = status.status_id
ORDER by customer.customer_corporate_name,SiretSiren