I would like to select a boolean of whether or not a column begins with a certain string.
SELECT (name LIKE 'foo%') AS isFoo FROM bar;
Is there a way to do this without using an inline CASE
?
No
There is neither implicit boolean CAST in SQL Server nor a boolean type
SELECT CAST(CASE WHEN name LIKE 'foo%' THEN 1 ELSE 0 END AS bit) AS isFoo
FROM bar;
You might not even need the cast depending on your usage:
SELECT CAST(PATINDEX('foo%'), name) AS bit) FROM bar
This will return 1 if the col starts with the text otherwise 0. No CASE
involved.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With