|
|
Question : equivalent function in sql for crystal function startswith
|
|
hi experts,
has anyone of you familiar with the command startswith of crystal? well, anyway.....i'm looking for an equivalent command in sql.
example:
in crystal
if variable starswith ['Desktop','Laptop'] then 'okay' else 'not okay'
will return
variable result Desktop PC okay Laptop Cover okay Desk not okay Lap not okay
thanks.
ann
|
Answer : equivalent function in sql for crystal function startswith
|
|
There is no function such as the one you are describing in T-SQL. There are a couple of other alternatives. If you can identify all of the starting values reliably with a fixed-number of starting characters, you could use the LEFT function.
SELECT CASE WHEN LEFT(@var,6) IN ('Deskto','Laptop') THEN 'okay' ELSE 'not okay' END AS decision
If you are just looking to simplify queries with this condition and aren't too worried about performance, you could place the values in a temp table or a permanent table and use the following syntax:
SELECT CASE WHEN EXISTS (SELECT val FROM yourtable y WHERE @var LIKE val+'%') THEN 'okay' ELSE 'not okay' END AS decision
Otherwise, you should use the the LIKE operator or the CHARINDEX function.
-Paul.
|
|
|
|
|