I getting an error in the following code stating that column is ambiguously defined but i have already changed the name of the columns within each sub query. I am not sure where the error is coming from, if i run every sub query separately it works fine but can't seem to find the specific error line.
With tskq as
(
Select SFDC_D2C_TASKS.ACCOUNTID,
Count(SFDC_D2C_TASKS.ID) Total_Tasks,
(Case when Sum(Case when SFDC_D2C_TASKS.CREATED_BY_ROLE__C like '%OE%' then 1 End)>1 then 'True' else 'False' end) OE_Task,
(Case when Sum(Case when SFDC_D2C_TASKS.CREATED_BY_ROLE__C like '%CLOS%' then 1 End)>1 then 'True' else 'False' end) CLOS_Task
From SFDC_D2C_TASKS
Group by SFDC_D2C_TASKS.Accountid
Order by SFDC_D2C_TASKS.Accountid Desc
),
discntq as
(
Select
ACCOUNT__C as discnt_ACCOUNT,
Override_PRICE__C as discnt_Override_Price,
PARENT_PRODUCT_FAMILY__C as discntP_Prod_Fam,
PRODUCT_FAMILY__C as discnt_Prod_Fam,
ORDER_PRODUCT_TYPE__C as discnt_Ord_Prod_type,
QUANTITY__C as discnt_Qty,
PRICE__C as discnt_Price
from SFDC_D2C_ORDER_PRODUCT
where PRODUCT_FAMILY__C like '%Discount%'
),
mgrq as
(
Select
SFDC_D2C_ACCOUNT_OBJECT.OSM__C,
SFDC_D2C_USER.ID as USER_ID,
SFDC_D2C_USER.Name
from SFDC_D2C_ACCOUNT_OBJECT
Left Join SFDC_D2C_USER on SFDC_D2C_ACCOUNT_OBJECT.OSM__C= SFDC_D2C_USER.ID
),
accntq as
(
Select
SFDC_D2C_ACCOUNT_OBJECT.ID as ACCOUNT_ID,
SFDC_D2C_ACCOUNT_OBJECT.CREATEDDATE as Account_Created_Date,
SFDC_D2C_ACCOUNT_OBJECT.BOOKING_DATE__C,
NVL(SFDC_D2C_ACCOUNT_OBJECT.ACCT_NUMBER__C,ACCOUNTNUMBER) as BAN,
SFDC_D2C_ACCOUNT_OBJECT.OWNERID,
SFDC_D2C_ACCOUNT_OBJECT.WEB_ID__C,
SFDC_D2C_ACCOUNT_OBJECT.ICI_CODE__C as Store_Code,
SFDC_D2C_ACCOUNT_OBJECT.COID__C,
SFDC_D2C_ACCOUNT_OBJECT.NAME as Customer_Name,
SFDC_D2C_ACCOUNT_OBJECT.OSM__C as OSM_ID,
SFDC_D2C_ACCOUNT_OBJECT.PROJECT_NAME__PC,
SFDC_D2C_ACCOUNT_OBJECT.TELUS_MANAGER__PC,
SFDC_D2C_ACCOUNT_OBJECT.D2C_ROLE__PC,
SFDC_D2C_ACCOUNT_OBJECT.SALESFORCE_USER__PC,
SFDC_D2C_ACCOUNT_OBJECT.OWNERID as Rep_ID,
(Case
when SFDC_D2C_ACCOUNT_OBJECT.SALES_ACTIVITY__C in ('RMP', 'EDGE Collateral' , 'TAP' , 'MDU Lobby Event' , ' CityPlace') then 'MDU'
else (
case when SFDC_D2C_ACCOUNT_OBJECT.SALES_ACTIVITY__C in('Door Knocking' , 'Referral' , 'Mall Event' , 'Back to School' , 'Falcon') then ' D2C' end)
end) as D2C_Channel,
SFDC_D2C_ACCOUNT_OBJECT.RTCA_COMPLETE__C,
SFDC_D2C_ACCOUNT_OBJECT.SALES_ACTIVITY__C,
SFDC_D2C_ACCOUNT_OBJECT.ACTIVITY_DETAIL__C,
SFDC_D2C_ACCOUNT_OBJECT.SPECIALEVENT__C,
SFDC_D2C_ACCOUNT_OBJECT.GIFT_PRODUCT_NAME__C,
SFDC_D2C_ACCOUNT_OBJECT.ORDER_STATUS__C,
SFDC_D2C_ACCOUNT_OBJECT.BOOKED__C,
SFDC_D2C_ACCOUNT_OBJECT.CANCEL_ALL_PRODUCTS__C,
SFDC_D2C_ACCOUNT_OBJECT.LIVE_ORDER_ENTRY_STATUS__C,
SFDC_D2C_ACCOUNT_OBJECT.TABLET_SUBMITTED_ORDER__C,
(Case when SFDC_D2C_ACCOUNT_OBJECT.BOOKING_DATE__C is not null then 'True' else 'False' end) as Softbooked
from SFDC_D2C_ACCOUNT_OBJECT
),
ordprdq as
(
Select
SFDC_D2C_ORDER_PRODUCT.ACCOUNT__C as ordpr_ACCOUNT,
SFDC_D2C_ORDER_PRODUCT.CREATEDDATE as Order_Product_Created_Date,
SFDC_D2C_ORDER_PRODUCT.BOOKED_DATE__C,
SFDC_D2C_ORDER_PRODUCT.PRODUCT__C,
SFDC_D2C_ORDER_PRODUCT.ORDER_PRODUCT_TYPE__C,
SFDC_D2C_ORDER_PRODUCT.PARENT_PRODUCT_FAMILY__C,
SFDC_D2C_ORDER_PRODUCT.PRODUCT_FAMILY__C,
SFDC_D2C_ORDER_PRODUCT.PRODUCT__C,
SFDC_D2C_ORDER_PRODUCT.QUANTITY__C,
SFDC_D2C_ORDER_PRODUCT.STATUS__C,
SFDC_D2C_ORDER_PRODUCT.STATUS_REASON__C,
SFDC_D2C_ORDER_PRODUCT.MIGRATION__C
From SFDC_D2C_ORDER_PRODUCT
),
prdctq as
(
Select
SFDC_D2C_PRODUCTS.ID as Product_ID,
SFDC_D2C_PRODUCTS.ACTIVE__C,
SFDC_D2C_PRODUCTS.PRICE__C
From SFDC_D2C_PRODUCTS
)
Select
accntq.ACCOUNT_ID
From accntq
Left Join ordprdq on accntq.ACCOUNT_ID =ordprdq.ordpr_ACCOUNT
Left Join ordprdq on prdctq.Product_ID=ordprdq.PRODUCT__C
Left Join mgrq on mgrq.ACCOUNT_ID=accntq.OSM__C
Left Join tskq on taskq.ACCOUNT__C= accntq.ACCOUNT_ID
Your ordprdq CTE is including SFDC_D2C_ORDER_PRODUCT.PRODUCT__C twice in its select list.
Related
This view script is missing a right parenthesis and I cant figure out where it is. I'd appreciate any help
I've tried debugging for hours and can't figure it out. I've even tried online sql checkers I'd appreciate any help or suggestions thank you for your time. Is there an online website that can determine the syntax error faster? :
CREATE OR REPLACE VIEW MY_VIEW_SCRIPT AS
SELECT * FROM
(
SELECT
EFFECTIVE_DT,
SOURCE_CD,
VIEW_CD,
SDEX_TRAN_CODE TRANSACTION_CD,
'missing' TRANSACTION_DESC,
'missing' TRANSACTION_CATEGORY_TXT,
'Y' TRANSACTION_CODE_ACTIVE_IND,
Trunc(SYSDATE) TRANSACTION_CODE_START_DT,
NULL TRANSACTION_REVERSAL_CD,
NULL PRINCIPLE_MULTIPLICATION_NBR,
NULL INCOME_MULTIPLICATION_NBR,
NULL SHARES_MULTIPLICATION_NBR,
NULL COST_MULTIPLICATION_NBR,
'INVEST1' ACCOUNTING_SYSTEM_CD
FROM TRD_FPCMS_TRANS_FULL_01_STG
WHERE SDEX_TRAN_CODE IS NOT NULL
AND SOURCE_CD != 'INSTIO'
UNION
SELECT
EFFECTIVE_DT,
SOURCE_CD,
VIEW_CD,
SDEX_TRAN_CODE TRANSACTION_CD,
'missing' TRANSACTION_DESC,
'missing' TRANSACTION_CATEGORY_TXT,
'Y' TRANSACTION_CODE_ACTIVE_IND,
Trunc(SYSDATE) TRANSACTION_CODE_START_DT,
NULL TRANSACTION_REVERSAL_CD,
NULL PRINCIPLE_MULTIPLICATION_NBR,
NULL INCOME_MULTIPLICATION_NBR,
NULL SHARES_MULTIPLICATION_NBR,
NULL COST_MULTIPLICATION_NBR,
'INVEST1' ACCOUNTING_SYSTEM_CD
FROM TRD_FPCMS_TRANS_FULL_01_STG
WHERE SDEX_TRAN_CODE IS NOT NULL
) stg
WHERE NOT EXISTS (
SELECT 1
FROM accounting_transaction_code tgt
WHERE tgt.TRANSACTION_CD = stg.TRANSACTION_CD)
UNION
SELECT
businessdt effective_dt,
holding_source_cd source_cd,
holding_view_cd view_cd,
txn.transaction_cd,
txn.tran_desc transaction_desc,
'missing' transaction_category_txt,
'Y' transaction_code_active_ind,
TRUNC(sysdate) transaction_code_start_dt,
NULL transaction_reversal_cd,
NULL principle_multiplication_nbr,
NULL income_multiplication_nbr,
NULL shares_multiplication_nbr,
NULL cost_multiplication_nbr,
'GENEVA' ACCOUNTING_SYSTEM_CD
FROM transactions_gva_kfk_stg tks, (
SELECT DISTINCT
CASE WHEN LEAD(transaction_cd) OVER (ORDER BY transaction_cd) = transaction_cd
THEN substr(transaction_cd,1,6)||substr(sys_guid(),6,6)
ELSE transaction_cd END transaction_cd,
tran_desc
FROM (
SELECT
CASE WHEN (
SELECT COUNT(1)
FROM accounting_transaction_code
WHERE transaction_cd = UPPER(substr(trxcd,1,12))
) = 0
THEN UPPER(substr(trxcd,1,12))
WHEN (
SELECT COUNT(1)
FROM accounting_transaction_code
WHERE transaction_cd = UPPER(substr(trxcd,1,6)||substr(trxcd,-6))
) = 0
THEN UPPER(substr(trxcd,1,6)||substr(trxcd,-6))
ELSE substr(trxcd,1,6)||substr(sys_guid(),6,6)
END transaction_cd, tran_desc
FROM (
SELECT DISTINCT
gva.trxcd tran_desc,
regexp_replace(UPPER(trxcd),'[^A-Z0-9]') trxcd
FROM transactions_gva_kfk_stg gva
WHERE NOT EXISTS
(SELECT 1
FROM accounting_transaction_code tgt
WHERE tgt.transaction_desc = gva.trxcd)
) ORDER BY transaction_cd)) txn
WHERE txn.tran_desc = tks.trxcd
AND NOT EXISTS
(SELECT 1
FROM accounting_transaction_code tgt
WHERE tgt.transaction_desc = tks.trxcd);
you seem to have added those 2 columns to only one of the SELECT statements, you need to add them to all the SELECT statements that are being UNIONed together. When you union select statements, each statement needs to return the same number of columns, with the same datatypes, in the same order
I am trying to add a condition to existing SQL Query but I am no expert at SQL & requesting some help here.
I have the below SQL query & I currently have PARNT_SLS_ORDER_LINE_KEY that I am pulling for two BUSINESS_UNIT_ID ('CSPBU', 'TMGBU'). In the existing query I am trying to add a condition like:
If PARNT_SLS_ORDER_LINE_KEY exists in both CSPBU & TMGBU then output or ignore.
SELECT
BV_PRODUCTS.PRODUCT_ID,
BV_FISCAL_DAY_TO_YEAR.FISCAL_YEAR_NUMBER_INT,
BV_FISCAL_DAY_TO_YEAR.FISCAL_QUARTER_ID,
SUM(CASE WHEN DT_MT_RSTD_BKGS_MEASURE_IE_BE.SERVICE_FLG = 'N' THEN DT_MT_RSTD_BKGS_MEASURE_IE_BE.EXTENDED_QUANTITY*COALESCE(BV_BE_HIER_PRDT_FAM_ALLOC_INT.PRDT_FAMILY_ALLOCATION_PCT,1)*COALESCE(BV_BE_HIER_PRDT_FMLY_ALLOC_EXT.PRDT_FAMILY_ALLOCATION_PCT,1) ELSE 0 END) Quanity
,
sum(CASE WHEN DT_MT_RSTD_BKGS_MEASURE_IE_BE.SERVICE_FLG = 'N' THEN DT_MT_RSTD_BKGS_MEASURE_IE_BE.COMP_US_NET_PRICE_AMOUNT*COALESCE(BV_BE_HIER_PRDT_FAM_ALLOC_INT.PRDT_FAMILY_ALLOCATION_PCT,1)*COALESCE(BV_BE_HIER_PRDT_FMLY_ALLOC_EXT.PRDT_FAMILY_ALLOCATION_PCT,1) ELSE 0 END) Net_Price,
BV_SALES_ORDER_LINE.PARNT_SLS_ORDER_LINE_KEY,
BV_PRODUCTS.BUSINESS_UNIT_ID
FROM
FINANCEBOBVDB.BV_PRODUCTS,
FINANCEBOBVDB.BV_FISCAL_DAY_TO_YEAR,
FINANCEBOBVDB.BV_BE_HIER_PRDT_FAMILY_ALLOC BV_BE_HIER_PRDT_FAM_ALLOC_INT,
FINANCEBOBVDB.BV_BE_HIER_PRDT_FMLY_ALLOC_EXT,
(
SELECT BV_MT_RSTD_BKGS_MEASURE.* , BV_FISCAL_DAY_TO_YEAR.FISCAL_YEAR_QUARTER_NUMBER_INT ,
BV_FISCAL_DAY_TO_YEAR.CALENDAR_DATE
FROM FINANCEBOBVDB.BV_MT_RSTD_BKGS_MEASURE , FINANCEBOBVDB.BV_FISCAL_DAY_TO_YEAR
WHERE BV_MT_RSTD_BKGS_MEASURE.BOOKINGS_PROCESS_DATE = BV_FISCAL_DAY_TO_YEAR.CALENDAR_DATE
AND BV_FISCAL_DAY_TO_YEAR.FISCAL_YEAR_MONTH_INT >= 201001
) DT_MT_RSTD_BKGS_MEASURE_IE_BE,
BV_SALES_ORDER_LINE
WHERE
( BV_BE_HIER_PRDT_FAM_ALLOC_INT.ITEM_KEY=DT_MT_RSTD_BKGS_MEASURE_IE_BE.PRODUCT_KEY AND BV_BE_HIER_PRDT_FAM_ALLOC_INT.FISCAL_YEAR_QUARTER_NUMBER_INT=DT_MT_RSTD_BKGS_MEASURE_IE_BE.FISCAL_YEAR_QUARTER_NUMBER_INT )
AND ( BV_BE_HIER_PRDT_FMLY_ALLOC_EXT.ITEM_KEY=DT_MT_RSTD_BKGS_MEASURE_IE_BE.PRODUCT_KEY AND BV_BE_HIER_PRDT_FMLY_ALLOC_EXT.FISCAL_YEAR_QUARTER_NUMBER_INT=DT_MT_RSTD_BKGS_MEASURE_IE_BE.FISCAL_YEAR_QUARTER_NUMBER_INT )
AND ( DT_MT_RSTD_BKGS_MEASURE_IE_BE.BOOKINGS_PROCESS_DATE=BV_FISCAL_DAY_TO_YEAR.CALENDAR_DATE )
AND ( BV_PRODUCTS.ITEM_KEY=DT_MT_RSTD_BKGS_MEASURE_IE_BE.PRODUCT_KEY )
AND ( BV_SALES_ORDER_LINE.SALES_ORDER_LINE_KEY=DT_MT_RSTD_BKGS_MEASURE_IE_BE.DV_SALES_ORDER_LINE_KEY )
AND ( DT_MT_RSTD_BKGS_MEASURE_IE_BE.PRODUCT_KEY IN ( SELECT ITEM_KEY FROM FINANCEBOBVDB.BV_PRODUCTS H JOIN FINANCEBOBVDB.BV_IAM_TECHNOLOGY_GROUP_LINK S ON H.TECHNOLOGY_GROUP_ID = S.TECHNOLOGY_GROUP_ID WHERE cec_id='meramesh' AND IAM_LEVEL_NUM=1 ) )
AND ( DT_MT_RSTD_BKGS_MEASURE_IE_BE.DV_ATTRIBUTION_CD IN ('ATTRIBUTED','STANDALONE') )
AND
(
DT_MT_RSTD_BKGS_MEASURE_IE_BE.REVENUE_RECOGNITION_FLG IN ( 'Y' )
AND
BV_FISCAL_DAY_TO_YEAR.FISCAL_YEAR_NUMBER_INT IN ( 2018, 2019, 2020 )
AND
BV_PRODUCTS.BUSINESS_UNIT_ID IN ( 'cspbu', 'tmgbu' )
)
GROUP BY
1,
2,
3,
6,
7
How are you grouping your rows -- by product_id? If you want to only return rows where a given product_id has PARNT_SLS_ORDER_LINE_KEY with both values of TMGBU and CSPBU, then you can add this to the end of your query:
QUALIFY
MAX(CASE PARNT_SLS_ORDER_LINE_KEY WHEN 'CSPBU' THEN 1 WHEN 'TMGBU' THEN 2 END)
OVER(PARTITION BY BV_PRODUCTS.PRODUCT_ID) <>
MIN(CASE PARNT_SLS_ORDER_LINE_KEY WHEN 'CSPBU' THEN 1 WHEN 'TMGBU' THEN 2 END)
OVER(PARTITION BY BV_PRODUCTS.PRODUCT_ID)
Give it a try and let me know.
I want to create a table using with clause:
For example :
with cte as
(SELECT B.STEUC "HSN",
CASE WHEN A.FORMAT_CD='520' THEN '2' ELSE A.FORMAT_CD END FORMAT_CD,
CASE WHEN A.FORMAT_CD='520' THEN 'DIGITAL' ELSE A.FORMAT_DESC END FORMAT_DESC,
A.ARTICLE,
A.REGION "STATE",
SUM(CASE WHEN BWART IN ('702','704','708','711','713','715','717','551','553','555','903','909','951','Z09') THEN DMBTR ELSE 0 END) -
SUM(CASE WHEN BWART IN ('701','703','707','712','714','716','718','552','554',' 556','904','910','952','Z10') THEN DMBTR ELSE 0 END) "LOSS_VALUE"
FROM "_SYS_BIC"."RRA.DnL/CV_STOCK_MOVEMENT" A INNER JOIN "P22"."MARA" B ON A.ARTICLE=B.MATNR
WHERE posting_date BETWEEN '20181101' AND '20181130' AND
BWART IN ('702','704',' 708',' 711','713','715','717','701','703','707','712','714','716','718','551',
'552','553','554','555','556','903','904','909','910','951','952','Z09','Z10') AND
A.COMPANY_CODE='9008' AND
A.LEVEL2 NOT IN ('10','99') AND
A.LEVEL5 NOT IN ('140601010') AND
A.FORMAT_CD NOT IN ('51','56','62','509')
GROUP BY B.STEUC,A.ARTICLE,A.REGION,A.COMPANY_CODE,A.FORMAT_CD,
A.FORMAT_DESC)
SELECT A.HSN,
A.STATE,
A.FORMAT_CD,
A.FORMAT_DESC,
A.ARTICLE,
A.LOSS_ART,
B.LOSS
FROM (
SELECT A.HSN,
A.STATE,
A.FORMAT_CD,
A.FORMAT_DESC,
A.ARTICLE,
A.LOSS LOSS_ART,
SUM(A.LOSS) OVER (PARTITION BY A.HSN,A.STATE,A.FORMAT_CD ORDER BY LOSS DESC) LOSS
FROM (SELECT A.HSN,A.STATE,A.FORMAT_CD,A.FORMAT_DESC,A.ARTICLE,SUM(LOSS_VALUE) LOSS FROM
--"RR_ANALYST"."REETIKA_LOSS_DATA_1"
cte A
INNER JOIN P22.MARA B ON A.ARTICLE=B.MATNR
WHERE B.ATTYP<>'11'
GROUP BY A.HSN,A.STATE,A.FORMAT_CD,A.FORMAT_DESC,A.ARTICLE
HAVING SUM(LOSS_VALUE)>0 ) A
) A ,
(SELECT A.HSN,A.STATE,A.FORMAT_CD,SUM(LOSS_VALUE) LOSS FROM
cte A
group by A.HSN,A.STATE,A.FORMAT_CD HAVING SUM(LOSS_VALUE)>0) B
WHERE A.HSN=B.HSN AND
A.STATE=B.STATE AND
A.FORMAT_CD=B.FORMAT_CD AND
A.LOSS<=B.LOSS*1
Which i guess is not supported in Hana.
What can be an alternative to the same ?
Does hana support spooling like oracle ?
I know i can export the result set and then create a table accordingly.
But is there any way to achieve and create the table dynamically ?
An alternative is the oldfashioned way - an inline view.
CREATE column TABLE t AS
SELECT *
FROM (SELECT 1 as some_value --> this is your WITH factoring clause
FROM dummy
UNION ALL
SELECT 2
FROM dummy
);
Just a question on displaying a row on flight level and displaying a count on how many crew members on that flight.
I want to change the output so it will only display a single record at flight level and it will display two additional columns. One column (cabincrew) is the count of crew members that have the 'CREWTYPE' = 'F' and the other column (cockpitcrew) is the count of crew members that have the `'CREWTYPE' = 'C'.
So the query result should look like:
Flight DepartureDate DepartureAirport CREWBASE CockpitCrew CabinCrew
LS361 2016-05-19 BFS BFS 0 3
Can I have a little help tweaking the below query please:
WITH CTE AS (
SELECT cd.*, c.*, l.Carrier, l.FlightNumber, l.Suffix, l.ScheduledDepartureDate, l.ScheduledDepartureAirport
FROM
(SELECT *, ROW_NUMBER() OVER(PARTITION BY LegKey ORDER BY UpdateID DESC) AS RowNumber FROM Data.Crew) c
INNER JOIN
Data.CrewDetail cd
ON c.UpdateID = cd.CrewUpdateID
AND cd.IsPassive = 0
AND RowNumber = 1
INNER JOIN
Data.Leg l
ON c.LegKey = l.LegKey
)
SELECT
sac.Airline + CAST(sac.FlightNumber AS VARCHAR) + sac.Suffix AS Flight
, sac.DepartureDate
, sac.DepartureAirport
, sac.CREWBASE
, sac.CREWTYPE
, sac.EMPNO
, sac.FIRSTNAME
, sac.LASTNAME
, sac.SEX
FROM
Staging.SabreAssignedCrew sac
LEFT JOIN CTE cte
ON sac.Airline + CAST(sac.FlightNumber AS VARCHAR) + sac.Suffix = cte.Carrier + CAST(cte.FlightNumber AS VARCHAR) + cte.Suffix
AND sac.DepartureDate = cte.ScheduledDepartureDate
PLEASE TRY THIS.
SELECT Flight,
DepartureDate,
DepartureAirport,
CREWBASE,
SUM(CASE WHEN CREWTYPE = 'F' THEN 1 ELSE 0 END) AS CabinCrew ,
SUM(CASE WHEN CREWTYPE = 'C' THEN 1 ELSE 0 END) AS CockpitCrew
FROM #Table
GROUP BY Flight, DepartureDate, DepartureAirport, CREWBASE
Please Try This:
select Flight, DepartureDate, DepartureAirport,CREWBASE,
count(case when CREWTYPE='F' then 1 end ) as CabinCrew,count(case when CREWTYPE='C' then 1 end ) as CockpitCrew
from Staging.SabreAssignedCrew
group by Flight, DepartureDate, DepartureAirport,CREWBASE
where clause did not work with WITH when i wrote where Prse ='h' it shows me an error 'Invalid column'
;with cT(FLDID ,FLD10 ,FLD610)
as
(
select * from Table556
inner join Table555 on table555.FLD9=FLD318
where FLD610=150
)
select case when fld609 <=12 then 'h' else 's' end as Prse,* from cT
where Prse ='h'
The with has nothing to do with it. You're only introducing Prse in the final SELECT clause - and you can't reference such columns from the WHERE clause (since WHERE logically runs before SELECT).
Did you want:
;with cT(Prse, FLDID ,FLD10 ,FLD610)
as
(
select case when fld609 <=12 then 'h' else 's' end as Prse, * from Table556
inner join Table555 on table555.FLD9=FLD318
where FLD610=150
)
select * from cT
where Prse ='h'
Try this one -
;WITH cte AS
(
SELECT
FLDID
, FLD10
, FLD610
, Prse =
CASE WHEN FLD609 <= 12
THEN 'h'
ELSE 's'
END
FROM dbo.Table556 t
JOIN dbo.Table555 t2 ON t2.FLD9 = t.FLD318
WHERE FLD610 = 150
)
SELECT *
FROM cte
WHERE Prse = 'h'