I am trying to return a boolean value within a SELECT clause using an assertion. The working code is below, but it uses a CASE statement which I find quite clumsy :
The two failed versions I've tried are below, with their associated error messages :
...and using a CAST :
I have another question related to this, which is How to Return TRUE/FALSE Values. As you can see, I'm currently working with string values, which is not my eventual intention.
Code:
SELECT [PR_PRODUCT]
,[PR_COST]
,CASE WHEN ([PR_COST]=0)
THEN 'TRUE'
ELSE 'FALSE' END AS [CostMissing]
FROM [DBManagement].[dbo].[vwCustStock]
WHERE ([PR_RANGE] In(70,91))
GO
Code:
SELECT [PR_PRODUCT]
,[PR_COST]
,([PR_COST]=0) AS [CostMissing]
FROM [DBManagement].[dbo].[vwCustStock]
WHERE ([PR_RANGE] In(70,91))
GO
Msg 102, Level 15, State 1, Line 4
Incorrect syntax near '='.
Code:
SELECT [PR_PRODUCT]
,[PR_COST]
,(DT_BOOL)([PR_COST]=0) AS [CostMissing]
FROM [DBManagement].[dbo].[vwCustStock]
WHERE ([PR_RANGE] In(70,91))
GO
Msg 102, Level 15, State 1, Line 4
Incorrect syntax near 'PR_COST'.
Comment