I would like to choose the boolean value of whether the column starts with a specific row.
SELECT (name LIKE 'foo%') AS isFoo FROM bar;
Is there any way to do this without using the built-in CASE?
CASE
No
SQL Server does not have an implicit logical CAST, not a logical type
SELECT CAST(CASE WHEN name LIKE 'foo%' THEN 1 ELSE 0 END AS bit) AS isFoo FROM bar;
You may not need a throw depending on your use:
SELECT CAST(PATINDEX('foo%'), name) AS bit) FROM bar
It returns 1 if the col begins with the text otherwise 0. No CASE.
A UNION CASE, . , 'foo%', , 'foo%'
UNION
'foo%'
- :
SELECT 1 AS [YourBoolean], 'fool' WHERE 'fool' LIKE 'foo%' UNION SELECT 0, 'fuel' WHERE 'fuel' NOT LIKE 'foo%' ORDER BY 1
( .)
User Defined, inorder, , foo.
gbn, , (, , )
SELECT CAST(CASE WHEN LEFT(name, 3)='foo' THEN 1 ELSE 0 END AS bit) AS isFoo FROM bar;
SELECT CASE WHEN name LIKE 'foo%' THEN 1 ELSE 0 END as isFoo FROM bar