Calculated field error

Syntax is okay but when I try to run it I get this error:

Severity: Error, Table: , Field: , RowID: , Text: Bad SQL statement.
Review the server event logs for details.
Query returned 0 row(s).
Query has no more records to return.
Query execution total time: 39.5891 ms.

Works fine after I remove the third line with the string. Is there a limit on the amount of functions I can run or am I writing something wrong? Any help would be greatly appreciated, thank you.

I am not a SQL or tech guru, but I would try making all the “then” results as text.

That did not work unfortunately, but I appreciate the response.

Hello Griffin,

Give this a try and wrap your numbers in ’ ’ and you cannot drop a NULL without ’ ’ or you must wrap that calculated field in a ISNULL or use COALESCE

SELECT TOP(5) PartNum, 
(CASE
	WHEN Erp.Part.PartNum like '%SC228%' then '1' 
	WHEN Erp.Part.PartNum like '%CM30%' then '2'
	WHEN Erp.Part.PartNum like '%MB3130%' then 'tt'
	else 'NULL' end) as Calc_Field1
FROM Erp.Part

If you’re going to use LIKE I would use a % as a wildcard. If you’re going to tell SQL what the context of that field is going to be then you’re better of using equal symbol

Hope this helps.

Kind regards,
Aaron.

Also can you tell me what the error is on the server side.

This seemed to work, thank you! I do not have access to the server logs unfortunately.